What is the difference between remove and unsetChild methods in layout? - layout

What is the difference between remove and unsetChild methods in layout?
For example (in poll.xml layout file):
<customer_account_index>
<reference name="right">
<action method="unsetChild"><name>catalog_compare_sidebar</name></action>
</reference>
</customer_account_index>
Why unsetChild and not just remove?

Remove nodes will be processed after all layout handles are merged, and are a good way to remove a block regardless of which layout handle loaded the block; you just want to get rid of it entirely for some handles! It also removes recursively, so all you need to specify is the layout handle.
On the other hand, you may only want to remove a block from a reference in a specific layout handle, in which case you should use unsetChild. It is often used to remove a block from a reference, but then re-insert the same block with a different position. This would not have been possible with remove.
In your very specific example, the magento developers used it to give magento some flexibility. Let's say I added a subpage for the account index page, and the following layout handles were loaded:
default
...
customer_account_index
customer_account_index_subpage
And now assume on this subpage I would actually want the 'catalog_compare_sidebar' block. If they had used 'remove', I would not be able to add this block (with this specific name) because 'remove' would be processed -after- I had added the block myself.
This allows you to easily make changes from one single file; local.xml.

Taking your code as an example,if you use unsetchild,compare sidebar block removed from right column,but you can use it anywhere like left column,footer etc..,remove removes entirely from the template,and cannot be used anywhere.
Remove the compare sidebar using remove and if you call it somewhere else,error will be thrown.

Related

TYPO3 imageManipulation focusArea in Frontend

Does anyone know how to use the TYPO3 focus area in the frontend?
TCA imageManipulation
If I use the crop attribute in the fluid-template
<f:image width="555c" height="312c" src="{article.teaserFile.uid}" treatIdAsReference="1" crop="{article.teaserFile.originalResource.referenceProperties.crop}" />
i get a serialized string in data-focus-area.
<img data-focus-area="{"x":786.1145320197,"y":96.682142857143,"width":271.44177339901,"height":270.05062857143}" src="/fileadmin/_processed_/9/b/csm_testimage_0bfc7bc724.jpg" width="657" height="566" alt="" title="Testimage">
Does the data need to be used by a JS library? Can someone recommend a library here? Because i didn't find a recommendation for a library which can handle focus Area and the attribute data-focus-area.
Or do i have to write a viewhelper giving the attributes e.g. for "jQuery focuspoint" to data-focus-x, data-focus-y, data-image-w, and data-image-h.
No, you don't need to rewrite the ViewHelpers. (It would be nice, if in the future it could be a bit better extendable then now however.)
But you can implement the jQuery Focuspoint. The only thing you need to do, BEFORE you starts the focuspoint plugin, you can transform this array into the needed values with jquery.
An exmaple from the FocusPoint documentation
$('.focuspoint').focusPoint();
So before this line, you can just simply add the values from the array as an own data attribute.
The form is different, but the logic is the same. So you have the x, y, width and height values in the focus-area array.
This would not work with responsify.js for example. It needs bottom, top, left, right values.
So yes... it won't work out of the box.
But NO, you don't need to change the PHP part, because you can solve it on the front end. (You need jQuery plugin anyway, so making some code before using it is easier.)
Changing those ViewHelpers is also a possibility of course, but you really need to rewrite their functionality (also the renderImage function to be concrete) and if you want to update it to a later version it could lead to problems.

Is it possible to render a part twice in one display type? - Orchard CMS

I have a content type, Events, that has a part "StartDate" that I need to show twice in the summary view. Is it possible inside placement.info to render the part in "this" zone AND "that" zone?
Render the zone twice
Probably not through just using the placement.info file but if you edit the .cshtml view you can just render a zone twice.
For a test I just edited my blog detail view to have this code:
#Display(Model.Content)
#Display(Model.Content)
It worked, and displayed it twice. It's something you should probably be careful with this as in that example it rendered out my Disqus comments twice which created a clash because the same id was used twice on a single page.
Fine tune it with Part Relocation
If you need to pull a single bit of content (a shape/part) out of an existing zone you can also do it with something called Part Relocation which is explained in this Orchard Harvest Session.
The basic idea is to use placement to isolate it into its own zone:
<Match ContentType="News" DisplayType="Detail">
<Place Parts_StartDate="MakeUpAZoneName" />
</Match>
(Note: the Match tag is just an example, its the Place you will need to put in whatever match you want)
And then you can render that out in your .cshtml file with #Display() like:
#Display(Model.MakeUpAZoneName)
... other html code ...
#Display(Model.MakeUpAZoneName)
You can't render same shape twice, but simply you can return combined shapes from your driver and render each shape in different zone.
No its not possible, Only the first one in the file placement.info works.

Stash : Conditional Content

First off, a caveat ... I am brand new to Stash. I've heard a lot about it but this is my first time actually playing with it. I get the concept, but am having a hard time figuring this one thing out.
I have a main "wrapper" file and everything within that wrapper stays the same. I would like the option however, to be able to toggle the sidebar on and off if I need to.
I wouldn't think I would need a totally separate layout wrapper would I?
Is there a way to use a boolean variable within stash? (e.g. 2col=TRUE) or am I thinking about it wrong?
Thanks in advance for your help!
Generally what I'd do here is setup multiple Stash gets within the wrapper. Then in your individual templates you can set both the sidebar and the main content area. For parts where you might be repeating content, like the opening and closing divs of a sidebar, you can always drop some snippets inside the stash.
You can also use exp:stash:not_empty [docs] to wrap around the div or container for your sidebar within the wrapper.
I usually use one wrapper for every template. It'll contain an {exp:stash:get name="content"} tag, like yours, which contains the only variable content within.
In my individual templates, I embed the wrapper at the beginning using a regular EE embed ie. {embed="includes/wrapper"}.
Then I stash the content to be inserted into the wrapper using the {exp:stash:set name="content"} tag.
This seems like what you're doing anyway.
If I want to conditionally show a sidebar, I might just pass a variable into the embed.
eg. {embed="includes/wrapper" show_sidebar="yes"}
In my wrapper I would do this:
{if embed:show_sidebar}
Sidebar stuff.
{/if}

Magento - display block but only show when I call it with getChildHtml

I have created a block and I have placed it in to the layout xml and it is showing correctly in my theme. My problem is that I actually don't want it to display until I explicitly call it with getChildHtml('myblock').
My block xml looks like this:
<block type="page/html" name="myblock" as="myblock" template="page/html/myblock.phtml"/ >
Anyone have a clue how to achieve this?
Thanks
Place your block inside another that is neither a core/list type nor calls $this->getChildHtml('') (note the empty string). That way it will not be shown automatically and you are free to call it at your discretion.

Unobtrusively add block in cart

For a module I'm working on, I want to add a block in the shopping cart screen, I want to do it unobtrusively and I'd like to place it beneath the cart content and before the other blocks (coupon, shipping estimation, totals, ...).
I've managed to do the unobtrusive part: an observer listens to controller_action_layout_load_before and if the FullNameAction is checkout_cart_index it adds a handle of my layout update xml file:
the observer:
public function showUpperGifts($observer)
{
$fullNameAction = $observer->getEvent()->getAction()->getFullActionName();
if ($this->_isEnabled &&
($fullNameAction == 'checkout_cart_index')) {
$layoutUpdate = $observer->getEvent()->getLayout()->getUpdate()
->addHandle('my_special_handle');
}
}
and the layout file:
<my_special_handle>
<reference name="content">
<block type="module/block" name="module_block" template="module/block.phtml"/>
</reference>
</my_special_handle>
With this, the content of my phtml file shows up, but I'm not able to place it where I want.
My first try was to use the before="name.of.block" attribute, but it doesn't work. If I use before="whatever" it goes before everything inside the checkout.cart block, and if I use after="whatever" it goes after everything. In short it doesn't take the content of before or after into consideration.
Looking at the XML layout files of Magento's core modules, I realized that those argument for before and after only appears when the blocks they are placing after or before are inside the right/left columns. So my guess is that it's something special for those columns.
So my question is, can I specify the location of my block inside content? And yes, how?
Another solution would be to load the block asynchronously, as I could then append to the div of my choice the result of the AJAX call, but I'd rather do it in a "normal" way if I can.
Thanks for reading :)

Resources