Monthly Archives: June 2013

How to Include Custom CSS and JS files On Home Pages only in Magento?

Hello friends today I write an article on How to Include Custom CSS and JS files On Home Pages only in Magento?

In magento it’s very easy to add our custom CSS and JS file. You didn’t add the tag for CSS and JS file to add in all pages rather than you have to just add that thing in your .xml file as I show below.

Step 1 : First find that  in your custom theme’s layout folder the cms.xml file exists or not. If cms.xml file is not created in your custom theme layout folder then just copy from the base folder and paste into that.

Step 2 : Now you pasted cms.xml file , then look for below code in cms.xml file.

    <cms_index_index translate="label">
        <label>CMS Home Page</label>
    </cms_index_index>

Step 3 : Now we add the CSS file from the skin CSS folder.

<cms_index_index translate="label">
<label>CMS Home Page</label>
         <reference name="head">
              <action method="addCss">
                 <stylesheet>
                           css/custom.css /*This is ur css path*/
                 </stylesheet>
              </action>
         </reference>
</cms_index_index>

Now we try to add JavaScript file from the skin JS folder.

<cms_index_index translate="label">
     <label>CMS Home Page</label>
         <reference name="head">
             <action method="addItem">
                   <type>skin_js</type>
                   <name>js/customJs.js</name>
              </action>
         </reference>
</cms_index_index>

Now we try to add JavaScript file from the /js folder.

<cms_index_index translate="label">
     <label>CMS Home Page</label>
         <reference name="head">
             <action method="addJs">
                   <script>myJs.js</script>
              </action>
         </reference>
     </catalog_product_view>
</cms_index_index>

Thanks for view this article.

Advertisements
Magento

How to get logged in user details in Magento?

Hello friends today I will explain you how to check the user is logged in or not and if it it logged in then how to fetch the detail of user in Magento.

For that you have to follow below code

<?php
 $CusSession=mage::getSingleton('customer/session');
    //Checking customer is logged in or not
    if($CusSession->isLoggedIn())
    {
        $customer    = $CusSession->getCustomer();    //get Customer object		
        $name        = $customer->getName();		
		$customerEmail = $customer->getEmail();
		$customerFirstname = $customer->getFirstname();
		$customerLastname = $customer->getLastname();		
		echo $customercustomername;
    }	
	else
	{
		echo "Customer is not logged in";
	}
?>

Hope it is helpful to you find customer details

Rules For Magento Developers.

The Rules are design by the Magento Commerce. So if you follow the below rules then it will help to developing a magento Application.

  • Rule 1: Do NOT edit the files in the base package
  • Rule 2: Do not create a custom theme inside of the base package
  • Rule 3: Create your customized themes inside of their own design package. Make directories atapp/design/frontend/your_custom_package/default andskin/frontend/your_custom_package/default and build your custom theme there.
  • Rule 4: Do not copy all the files from base/default into your custom package. Copy only the files that you modify.
  • Rule 5: Do not create your custom theme inside of the default/default directories, even though there are old instructions that may tell you to do so. This approach was never recommended.
  • Rule 6: Do not copy all the files from default/default into your custom package as a starting point, even though there are old instructions that may tell you to do so. This approach has been deprecated.
  • Exception to Rule 6: Because base/default does not contain full CSS files, you may want to copy the CSS from one of the demo themes into your new custom themes as a starting point. Many designers and developers prefer to start with nothing and build their CSS from scratch though, so you can do this too. In general, if you do copy over CSS and image files to your new custom package, the blank theme (default/blank) provides the leanest CSS.
  • 2nd Exception to Rule 6: Enterprise customers for now DO need to copy the files from enterprise/default into their custom package as a starting point. In a future release, the Enterprise files will be folded into the base/default directories but they are not in EEv1.8.
  • Rule 7: Break the rules if you have to, just do so knowingly.

All rules are taken from the 

http://www.magentocommerce.com/knowledge-base/entry/magentos-theme-hierarchy