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.
Related
i'd like to find a way to call [[*content]] of every page in one template. I mean something still dynamic so that I could add or remove pages and it would appear in the menu without modifying anything.
http://fr.wix.com/website-template/view/html/tokyo-design
I want to use this kind of navigation with modx. Maybe getresource is the answer but I need to display something like this:
<div>[[*contentpage1]]</div>
<div>[[*contentpage2]</div>
<div>[[*contentpage3]]</div>
...
Could someone help me with this?
Thank you
Sounds like you are on the right track, using GetResources should be able to do this for you:
"
[[!getResources:default=``? &parents=`0` &includeContent=`1` &tpl=`contentoutput`]]
"
Then create a new chunk called "contentoutput" which contains the code you want to output, e.g.
"
<div>
[[+content]]
</div>
"
I have an alternate view for a widget. In that view I'm suppressing the wrapper using code like this:
Model.Metadata.Wrappers.Clear();
This works, but I'd like to only suppress the Widget.Wrapper. Right now it is also suppressing the Widget.ControlWrapper which prevents the edit buttons from displaying when I have the Widget Control Wrapper module enabled.
Is there any way to clear only the Widget.Wrapper while keeping the Widget.ControlWrapper?
In case anyone comes across this for a similar problem, I was able to suppress the Widget.Wrapper thusly in a Widget-Sidebar.cshtml file in my theme:
#using Orchard.DisplayManagement.Descriptors;
#using Orchard.Environment.Extensions;
#{
Model.Metadata.Wrappers.Remove("Widget_Wrapper");
Model.Metadata.Wrappers.Add("Widget_SideBarWrapper");
Model.Metadata.Wrappers.Add("Widget_ControlWrapper");
}
#Display(Model.Content)
I started out by using the Shape Tracing tool to create an alternate for widgets I had in a "sidebar" column (basically a <div id="sidebar"> I have in my layout as #Zone(Model.Sidebar)).
I placed the code above in the Widget-Sidebar.cshtml alternate that I created using Shape Tracing.
Model.Metadata.Wrappers.Clear(); as used by the OP completely removes everything, to the point where in Shape Tracing it won't even show up as a widget. Adding my own alternate (Widget.SideBarWrapper.cshtml, which is added as "Widget_SideBarWrapper" above) would not fix this. I felt that was wrong even though the content displayed.
Model.Metadata.Wrappers.Remove("Widget_Wrapper");
seemed the right way to go (i.e., Shape Tracing still showed a Widget), but it appears to REMOVE all the other wrappers, so you then have to add your new wrapper along with Widget.ControlWrapper.cshtml (written as "Widget_ControlWrapper" in code above).
HTH.
I was able to add back the Widget.ControlWrapper like this:
Model.Metadata.Wrappers.Add("Widget_ControlWrapper");
This seems to be working just like I wanted.
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}
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.
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 :)