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.
}
Related
I am using Magento 1.8.1 and I am working on SEO. I need to put micro-data (schema code) for some category on that page only. I don't understand how to put the data for specific page because if I put any data in template page, it will update on all categories.
For example: I need to put data only for this page.
As I understand it, you want to add some code to only appear on a specific category view. You can add Javascript to the description field in the General Information tab of the category:
You can also add a template to before_body_end block of the page:
You can add additional layout directives here. This layout update:
<reference name="before_body_end">
<block type="core/template" name="seocode" template="seocode/seocode.phtml" />
</reference>
means render out your custom block (seocode) and template file (seocode.phtml) in the before_body_end block. The before_body_end block can be found in the page templates; i.e. page/1column.phtml or page/2columns-left.phtml.
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
Please help me on this. I want to change template page layout of cart page in magento.
The following is the URL : http://www.wildgoosetrading.com/index.php/checkout/cart/
I want this to look like other pages of category.
Thanks in advance.
You'd set the template for the cart in your checkout.xml layout file.
In the checkout_cart_index section (straight after <default>) look for the following block and change the template the cart page is using;
<!-- Mage_Checkout -->
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
EDIT
I know this is the accepted answer but soipo's answer is the better way. Apply the change to local.xml, don't modify the core layout files, override them using local.xml in your theme's layout. See http://www.classyllama.com/development/magento-development/the-better-way-to-modify-magento-layout
In your local.xml file you can just add the following:
<checkout_cart_index translate="label">
<reference name="root">
<action method="setTemplate"><template>page/3columns.phtml</template ></action >
</reference>
Just change the template to the one you need.
By using Magento's common setTemplate method, the inherent granularity introduced by Magento's own app/design/frontend/base/default/layout/checkout.xml is lost.
Magento deliberately created two methods for doing this: setCartTemplate and setEmptyTemplate. They handle two separate conditions.
One condition is when the cart has items, the other is when the cart is empty. By calling setTemplate, that granularity is lost. That means a cart with items and a cart with zero items will both display the same template, which might be not desired.
More on this can be found here: https://stackoverflow.com/a/33875491/2973534
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