How to disable a remove statement from local.xml in Magento - layout

Is it possible to disable a <remove name="left"> statement defined in a default layout .xml file, from the local.xml file?
For example, in the checkout.xml in the <checkout_cart_index> section, the statement <remove name="left"/> is defined there, but can you disable that line from the local.xml file, so you still see the left menu on the checkout page?

By default Magento doesn't provide an <unremove /> tag for local.xml. However, the Layout system contains the right events, such that you can implement this yourself. And by "yourself", I mean I've created an experimental extension that adds such a tag. Feedback is welcome.

The two ways I do this are;
Use Alan Storm's excellent unremove plugin above.
Re insert the removed block in local.xml with a new name attribute but the same alias or 'as' attribute.
The name attribute needs to be different because Magento's <remove name="foo" /> is global - it removes all instances of <block name="foo" /> even if they are added after the remove instruction. To re add the left column, for example;
<reference name="root">
<block name="left.2" as="left" type="core/text_list">
<!-- New left column is empty, so you'll need to add your left-column blocks into it here. -->
</block>
</reference>
name="left.2" means the remove action won't kill this block, as="left" means that it will still be inserted into your template via <?php echo $this->getChildHtml('left') ?>.
Unfortunately, your newly inserted left column is empty. So you'd have to re insert any blocks in there that you want to show as well. Making Alan Storm's plugin all the more useful, I think.

When a block is removed it is not destroyed, only ignored. You might be able to 're-enable' it with:
<checkout_cart_index>
<reference name="root">
<action method="append"><block>left</block></action>
</reference>
</checkout_cart_index>
I've never used this myself and wouldn't want to, if you are making a custom theme then copy the base layout files and edit them directly just as the other answers recommend.

your answer is not to disable the removal but to add it again in your local.xml

Rather than trying to reconstruct the entire set of blocks, comment the remove inside the original XML. This will be less of a maintenance headache than trying to reconstruct the blocks and worrying about precedence of the XML files, etc.
Turn this
<remove name="left" />
Into
<!-- disabling remove because X -->
<!-- <remove name="left" /> -->

Related

Magento: local.xml doesn't show block

So I have empty package where is stored local.xml
(Paths I don't describe here, all caches disabled, error logs turned on).
I've added static block in admin panel. It is named "two_level_links".
Then I added code to local.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="header">
<remove name="top.links"/>
<block type="cms/block" name="topTwoLevelLinks">
<action method="setBlockId">
<block_id>two_level_links</block_id>
</action>
</block>
</reference>
</default>
</layout>
In the header phtml file call it:
<?php echo $this->getChildHtml('topTwoLevelLinks') ?>
top.links disappeared but topTwoLevelLinks didn't appear.
Then I looked at Mage_Core_Model_Layout_Update and set a var_dump for getFileLayoutUpdatesXml [$layoutXml]. The source has my block.
Cannot understand what I should do next. How to debug it? Or where I'm doing wrong?
everything looks fine, but let me suggest you to check next things:
Check in admin panel if your block is enabled.
If you have more than one store view, please check if you your block is associated to your current store view, that you see on the frontend
Check in which folder header.phtml file is placed. For example if you changed the header.phtml from your base theme folder "app/design/frontend/base/default", Magento never will know about it if you also have header.phtml in "app/design/frontend/custom_package/custom_theme/" ... if it is not clear enough, please read: http://www.magentocommerce.com/knowledge-base/entry/magentos-theme-hierarchy

How to remove a specific block from right column which must be shown on rest of the pages?

I had created a static block containing images aligned vertically then I added an xml block for calling it in the right column in catalog.xml.
Now it is showing that block on all pages .
BUt I dont want just this specific block to be displayed on detail page . So how can I restrict it not to be shown on detail page while showing on rest of the pages.
I did tried to remove it by this:
<remove name="right.info" />
And this is the block I'm calling:
<block type="core/text_list" name="banners">
<block type="cms/block" name="right.info">
<action method="setBlockId"><block_id>right_logos</block_id></action>
</block>
</block>
<reference name="banners">
<action method="unsetChild"><name>right.info</name></action>
</reference>

Magento login and register form one page

I am trying to combine the login form and create account form in Magento into one page. The reason is i just think the fewer pages the better. I find Magento confusing and have limited understanding of its layout and template system. I decided the easiest way to do this would be to just add the login form to the register account page. I found the login form and register form in login.phtml and register.phtml in template/customer/form/.
I simply copied the PHTML code from login.phtml into the register.phtml file that is in the same directory. This is what I ended up with:
http://pastebin.com/fpkeBsxc
After I fill in the email and password of an account and click login, the page returns with validation errors referring to the register account form bellow it. Basically, I'm not sure if this is because my approach is completely stupid/wrong and I can't just copy and paste code like this, or is this a simple html problem that I can't see? I think might be wrong way, as register form works. I'll post a screenshot of this in a comment, it won't let me paste more than one link. Thanks for any advice.
<reference name="content">
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml">
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml" />
</block>
</reference>
by this u can put html where do u want to place in customer/form/login.phtml
<?php echo $this->getChildHtml('customer_form_register') ?>
In customer.xml within your theme you can move the account register block to within the login page.
<customer_account_login translate="label">
<label>Customer Account Login Form</label>
<!-- Mage_Customer -->
<remove name="right"/>
<remove name="left"/>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
<block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label">
<label>Form Fields Before</label>
</block>
</block> </reference>
</customer_account_login>
In order to merge the customer registration form with the default login form of Magento, just note the following steps:
1. Creating mini.register.phtml file
First you need to create a new template file: app/design/frontend/[your-interface]/[your-theme]/template/customer/form/mini.register.phtml
And copy the contents of default register file: app/design/frontend/base/default/template/customer/form/register.phtml to the mini.register.phtml and customize as per your requirement.
2. Including mini.register.phtml in login.phtml
First copy the file: app/design/frontend/base/default/template/customer/form/login.phtml to your current theme as:
app/design/frontend/[your-interface]/[your-theme]/template/customer/form/login.phtml
And now you need to modify the new login.phtml so that you can include the contents of mini.register.phtml.
For this, you have to use the following xml code in your layout xml file (preferably in app/design/frontend/[your-interface]/[your-theme]/layout/local.xml) as:
<customer_account_login translate="label">
<reference name="content">
<action method="unsetChild"><child>customer_form_login</child></action>
<block type="customer/form_login" name="customer_form_login2" template="customer/form/login.phtml" >
<block type="customer/form_register" name="customer_form_register2" template="customer/form/mini.register.phtml">
<block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" />
</block>
</block>
</reference>
<reference name="head">
<action method="setTitle" translate="title" module="customer"><title>Login or Create an Account</title></action>
</reference>
</customer_account_login>
Now you can simply include the mini.register.phtml in your new login.phtml file as:
<?php echo $this->getChildHtml('customer_form_register2'); ?>
You're done.
Now clear the cache and reload the customer login page: http://your-mage-store/customer/account/login
You should do it slightly different:
get to know the magento layout and how it works
use layout references to include both existing forms in to one template
let them submit to their existing controllers

Magento Layout.xml <remove ...> tag not having desired effect

I have a "auth-redirect" module that is in the beginning of all my page layout files (1column, 2column, etc). This works to make sure that before rendering any page, if the user is not authenticated properly then it redirects to a login page.
The way that I allow the login page to render is in my customer.xml file I declare the following:
<customer_account_login>
<remove name="auth-redirect"/>
...
</customer_account_login>
This works fabulously.
However I recently created another module custom module and when I go to the urls that engage that module's controller and render the modules layout the auth-redirect stays in the page and thus I always get redirected.
The custom module layout looks like this:
<shipment_management_index>
<remove name="auth-redirect"/>
<reference name="content">
<block type="custom/vendor_shipment_info" template="custom/vendor/shipment/info.phtml" name="info"/>
</reference>
</shipment_management_index>
Now, I've gone to the page and using Alan Storm's showLayout module gotten the output from ?showLayout=page. You can see that the element for auth-redirect is in the page, down below the body, but at the top auth-redirect is still in the page. What am I missing?
<layout><block name="formkey" type="core/template" template="core/formkey.phtml"/>
<block type="page/html" name="root" output="toHtml" template="page/1column.phtml">
<block type="page/html" name="auth-redirect" as="auth-redirect" template="page/html/auth-redirect.phtml" ignore="1"/>
<block type="page/html_head" name="head" as="head">
...
</block>
...
<remove name="auth-redirect"/>
<reference name="content">
<block type="custom/vendor_shipment_info" template="custom/vendor/shipment/info.phtml" name="info"/>
</reference>
</reference></layout>
Is your last piece of code in the same file ? If so, why not trying to comment/delete the first
<block type="page/html" name="auth-redirect" as="auth-redirect" template="page/html/auth-redirect.phtml" ignore="1"/>
If not, maybe the code below will work if the "auth-redirect" block you want to remove is nested into the "formkey" block.
<reference name="formkey">
<action method="unsetChild"><name>auth-redirect</name></action>
</reference>

DIV identified by WebDevToolbar isnt in file?

I'm trying to use Magento for my shopping cart and want to switch from a right col layout to left col. I've turned on ID/CLASS display on the Web Developer Toolbar in firefox, and am seeing ".main col2-right-layout", which i believe i must switch to ".main col2-left-layout", the alternate style is predefined. but running searches for files with the phrase "col2-right-layout" in them is only pulling up the style sheet. I am searching THE ENTIRE Magento directory. How is this possible? Not case sensitive, and I'm even searching hidden folders. How can it be?
**i have looked in that file, the div is not mentioned. **
Files are in app/layout/default/default/templates/page/
I've not got a dev copy of magento at home, thats all I can remember off the top of my head - will try and remember to confirm when at work.
If you want to swap the templates, you need to look in app/layout/default/default/layout/page.xml, plus some of the other xml files - the templates are defined there.
(Yes, magento's layout/templating system is complicated, and has a steep learning curve, but its worth it!)
col2-right-layout is mentioned in
app/design/frontend/base/default/template/page/2columns-right.phtml
or in Magento 1.3
app/design/frontend/default/default/template/page/2columns-right.phtml
If you want to swap the layout I'd suggest changing it in one of the layout xml files. For the shopping cart edit app/design/frontend/base/default/layout/checkout.xml
change
<checkout_cart_index translate="label">
<label>Shopping Cart</label>
<remove name="right"/>
<remove name="left"/>
<!-- Mage_Checkout -->
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
to
<checkout_cart_index translate="label">
<label>Shopping Cart</label>
<remove name="right"/>
<remove name="left"/>
<!-- Mage_Checkout -->
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
</reference>
And similarly for the checkout page in the same file change
<checkout_onepage_index translate="label">
<label>One Page Checkout</label>
<!-- Mage_Checkout -->
<remove name="left"/>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
</reference>
to
<checkout_onepage_index translate="label">
<label>One Page Checkout</label>
<!-- Mage_Checkout -->
<remove name="left"/>
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
</reference>
As always it is better to make a copy of the file you are editing to your own theme.

Resources