Could you please tell me if it's possible to turn off loading of styles.css from
default/default/css when I use theme default/my_theme and that doesn't have styles.css?
Why does magento load for other theme styles.css from default/default?
Create a local.xml in your theme, in your <default> handler use
under reference head
removeItem to remove it
Try this.
Define layout.xml
This layout xml file is a unique layout file, that will be processed at last by Magento. This makes this layout file extremely good to remove/change layout appearance. Here you need to remove a css file. So you can use this.
File : app/design/frontend/<package>/<theme>/layout/local.xml
<layout>
<default>
<reference name="head">
<action method="removeItem">
<type>skin_css</type>
<name>css/styles.css</name>
</action>
</reference>
</default>
</layout>
Description
head is a special block that is used to hold css and js files. styles.css resides in this block. It is included through page.xml layout file.
<action method="addCss"><stylesheet>css/styles.css</stylesheet></action>
This is how it is included to head section. Here the action takes place addCss. This method uses a type skin_css by default. ie any css file that resides in skin directory can included by this method. You can also use addItem method. But you need to specify type attribute as skin_css, in order to use that method.
In order to remove an item that is added by addCss or addItem method, you can use removeItem. This method accepts two parameters. type and name. In our case type is skin_css (since styles.css resides in skin) and name is css/styles.css.
Hope that helps
Related
How can I add a custom code i.e. Facebook retargetting or conversion pixel, etc. to a section of a SPECIFIC page? (not global)
I am using the latest magento version.
Thanks
You can accomplish this cleanly using Magento’s layout system. Create or modify the local.xml file in your current theme’s layout subdirectory. Add a new layout update like this:
<!-- Add Facebook retargeting pixel on success page. -->
<checkout_onepage_success>
<reference name="before_body_end">
<block type="core/template" name="fb_retargeting" template="tracking/fb_retargeting.phtml"/>
</reference>
</checkout_onepage_success>
Notice that this layout update is targeting the <checkout_onepage_success> handle, which corresponds to the /checkout/onepage/success page. If you need to target a different page, you have to figure out the layout handle for that page. The handle is created by combining the route name, controller name, and controller method into a single underscore-separated string.
Now you just need to create your template file in your current design’s template subdirectory. In my above example, the template being referenced should be created at: app/design/frontend/.../template/tracking/fb_retargeting.phtml. You would just put the markup for your tracking pixel in that file.
1) If its going to be a CMS pages you can add in the design tab Layout Update XML and add custom xml code, for example
<reference name="head">
<block type="module/block" name="module" template="module/view.phtml" ></block>
</reference>
2) If this need to be in other pages, you can add same code in local.xml of your theme file
go to app/design/frontend/base/your theme/template/page/html/head.phtml
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
$url = Mage::getSingleton('core/url')->parseUrl($currentUrl);
$path = $url->getPath();
if($path == your specic page url){
your code.
}
Having trouble setting a block template in Magento's layout xml. I'm attempting to set the template of a child block, not the entire page layout (almost all docs out there explain how to set template of the layout).
Background: I'm updating a layout handle in my custom action, using the <update /> tag in my module's layout xml.
Essentially, I want to reuse the layout and blocks of the built in product view action, but provide custom templates for a few blocks. (Not just overrides, these need to be brand new templates that are only triggered on my custom action and are themselves overrideable).
My layout html:
<?xml version="1.0"?>
<layout version="0.1.0">
<mymodule_product_index>
<update handle="catalog_product_view" />
<reference name="content">
<block type="catalog/product_view"
name="product.info" output="toHtml" template="mymodule/product.phtml" />
</reference>
<reference name="product.info.bundle">
<action method="setTemplate"><template>mymodule/customtemplate.phtml</template></action>
</reference>
</mymodule_product_index>
</layout>
The setTemplate on product.info.bundle never works; it doesn't seem to affect layout at all. I've tried wrapping the <reference> in other <reference> nodes from parent blocks with no effect. Is it possible to replace block templates in this way? I feel that my problem stems from the fact I'm using an <update />.
By the way, I know my layout xml is being loaded and there are no errors, the rest of the file is working fine, caching is disabled, have cleared cache anyway, etc.
Your approach is almost correct.
Two things:
1. Set a new template instead of instantiating a new block
Instead of just assigning a different template to the product.info block, you are creating a new instance with the same name, replacing the original instance, and then the new template is set on that. Instead use this:
<mymodule_product_index>
<update handle="catalog_product_view" />
<reference name="product.info">
<action method="setTemplate">
<template>mymodule/product.phtml</template>
</action>
</reference>
</mymodule_product_index>
That should take care of the product view template in a clean way.
2. Handle processing order
If you look at where the view block product.info.bundle for the bundled products is declared, you will see it happens in the bundle.xml file, in a layout update handle called <PRODUCT_TYPE_bundle>.
Your code is referencing the block from the <[route]_[controller]_[action]> layout handle, i.e. <mymodule_product_index>.
The thing to be aware of here is the processing order of layout handles.
Roughly it is:
<default>
<[route]_[controller]_[action]>
<custom_handles>
The <PRODUCT_TYPE_bundle> handle belongs to the third type of layout handles, which means it is processed after the <mymodule_product_index> handle.
In essence, you are referencing the block product.info.bundle before it has been declared.
To fix this you will need to use the <PRODUCT_TYPE_bundle> handle as well. Of course this will effect every bundled product display. Using layout XML only there is no clean way around that.
Here are a few suggestions how to solve that problem.
You could create a separate route in your module to show the bundled products, and then include the <PRODUCT_TYPE_bundle> handle using an update directive for that page, too.
In your custom action controller, you could add another layout update handle that is processed after <PRODUCT_TYPE_bundle>.
You could use an event observer to set the template on the product.info.bundle block if it is instantiated. One possibility would be the event controller_action_layout_generate_blocks_after.
You get the idea, there are many ways to work around this, but they require PHP.
What is the code to pull in a custom view.phtml file via custom layout update (in admin > catalog > manage products > specific product) with magento? I would really like to do this in local.xml for specific products.
I found this:
<PRODUCT_ATTRIBUTE_SET_shirts>
<reference name="product.info">
<action method="setTemplate"><template>my/custom/product/view.phtml</template></action>
</reference>
But this code is for attributes.
Well, I don't think you can do that in local.xml. But Custom Layout Updates were made for situation like that. Just write there your XML:
<reference name="product.info">
<action method="setTemplate"><template>my/custom/product/view.phtml</template></action>
</reference>
Or if you need to apply the same view.phtml for several products, you can create a new theme containing just one catalog/prodcut/view.phtml and make it extend your current theme. Then apply this theme only for products you need.
I am not entirely sure what you are asking for, but I am guessing you want to use your own view.phtml file and don't know how to have the xml layout file point to that new file.
first look for the file:
app/design/frontend/YOUR_THEME/default/layout/catalog.xml
This file essentially controls what blocks will be called within the catalog of products. If you look for the line:
<reference name="content">
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
You can change the template= portion to point to your custom view.phtml file. Just remember that the file structure starts at the template file:
app/design/frontend/YOUR_THEME/default/template
So you will need to store your view file within that template file if you use this method.
I hope this helps!
How do you add a class to a div in a Magento layout? I want to change it on only one of my pages. By default, I have:
<div class="col-left sidebar">
I want:
<div class="col-left sidebar my-class">
I can't change this in 2-columns-left because it will change on all pages of Magento. Is it possible?
If you just want to change one page, you could try copying the 2-columns-left template, renaming and editing it, then editing the page to use the new template.
Rename and edit the 2-columns-left.phtml file. This is found in /app/design/frontend/default/YOUR_THEME/template/page . At around line 50 you'll see the <div class="col-left sidebar"> line.
Edit the config.xml file so that the page uses the new template. Config.xml is in /app/code/core/Mage/Page/etc . About halfway down you'll see code referring to two_columns_left; copy this code, and edit it to point to the new page.
Finally, edit the page through the backend > CMS > Pages to use the new template. You can now add styles through the CSS in your theme.
More instructions here.
Method 1 - layout.xml :
a. For files you want to include on every page
For css or js files you want to add to every page, you edit the page.xml files located in your layout folder (app/design/frontend/default/your_theme/layout/page.xml). Within this file, at the top you will find the <default> area with the **<block name="root" … >**. This block has a child named head which contains the included css and js elements.
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs" ifconfig="dev/js/deprecation"><script>prototype/deprecation.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
...
</block>
Here you can add your javascript and css. Note that any Js files you add are relative to the “js” folder in your root directory. The css files are included from the skin files of the current and default templates (skin/frontend/default/your_template(& default)/css).
b. Specific areas
If you want to include css or js on only certain areas (such as the checkout process or catalog pages), you can do that also. For instance, if you want it in a single product view (product view vs product list), you can open up catalog.xml, find <catalog_product_view> area (near line 168 in vs 1.2.1). Add your code in there – notice that we are using the <reference> tag rather than <block> tags. We use the “reference” tag to reference other blocks that are in other areas of the template.
<reference name="head">
<action method="addJs"><script>varien/product.js</script></action>
<action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/lang/calendar-en.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
</reference>
The use of can also be used in your layout XML areas in the admin backend (CMS pages, category and product designs). This can accomplish the same thing, as well as adding or removing other blocks.
Method 2 - Block Code :
We can accomplish all of this in code as well. These functions are defined within Mage_Page_Block_Html_Head. So, we can use this code with in a block class (not a .phtml file!):
$headBlock = $this->getLayout()->getBlock('head');
$headBlock->addJs('somefolder/yay.js');
I suggest looking over the page.xml files as long as finding the removeItem syntax ($type, $name for the method, for the xml), which will be very handy for you for adding or removing assets as and when you need them!
<action method="removeItem"><type>js</type><name>calendar/calendar.js</name</action>
$this->getLayout->getBlock('head')->removeItem('js', 'calendar/calendar.js');
The article was published : http://www.exploremagento.com/magento/adding-and-remove-js-css.php
I am using this code in my template file to display a static block in my left sidebar:
<?= $this->getLayout()->createBlock('cms/block')->setBlockId('leftSB1')->toHtml() ?>
I would like to exclude the block from one of my CMS pages. How do I do this?
I think it requires adding code to the 'Layout Update XML' section but I'm not sure what exactly.
Someone else can correct me here, but I'm fairly sure that you're going to have trouble trying to accomplish this given the way you called the block. Normal layout updates allow you to remove blocks, but those are blocks that were also created with the layout (e.g. the Layout object knows about them after you call loadLayout()).
In your case, you create the block on the fly and then immediately use it to echo some HTML. If you want to be able to delete it with layout updates, try moving it into the layout files first, then use the normal layout block removal method:
<reference name="your_parent_block_name">
<remove name="leftSB1"/>
</reference>
Otherwise, you could hide it either in the PHP (By setting some global variable and checking it before outputting the block. Poor form but it might work.) or in CSS. Let me know if any of these work for you.
Thanks,
Joe
Include the block in your layout instead:
<cms_page>
<reference name="left">
<block type="cms/block" name="leftSB1">
<action method="setBlockId"><id>leftSB1</id></action>
</block>
</reference>
</cms_page>
And then $this->getChildHtml('leftSB1') in your sidebar, if you're not including children automatically.
(and then remove it from the particular page as in the previous answer)