Turning On and Off Magento's Default Blocks

piaoling  2011-04-25 10:31:09

Turning On and Off Magento's Default Blocks

When customizing your Magento store, one of the first things everyone wants to do is to turn off some of the default functionality and modules. Out of the tarball, Magento has most of its functionality turned on so that it's available, but some will not be applicable to your store. This article summarizes how to turn off some of default modules and blocks of content, like the callout banners in the right and left columns, or the poll, or newsletter signup.

The general process we recommend when starting to customize your Magento store is to start simple and move up to more complex solutions only if you need to. To ensure the best upgrade path and most stable behavior, follow this approach when customizing:

  1. Can you disable or customize the feature/module using the Admin Panel?
  2. Can you disable or customize the feature/module using the layout (xml) files & CSS?
  3. Can you disable or customize the feature/module using the template (phtml) files & CSS?
  4. Do you have to write a custom module or local extension?

This article covers how to turn off some of the most commonly modified blocks and modules on your Magento website using the Admin Panel and your custom theme’s xml files (steps 1 & 2 above). It doesn’t provide every bit of code but should point you in the right direction for some of the most common elements. Guidance here will vary based on what version of Magento and what theme is being used, so we’ve tried to explain the general approach then you can adapt the specific admin fields or code snippets depending on your theme and version of Magento.

In this article....

Common Elements You Can Turn Off (and On) Via the Admin Panel

Below are some of the blocks and elements that you can turn off using the Admin Panel. The key advantages of turning off elements using the Admin Panel are that you don’t have to mess with any code and doing so ensures your changes are independent of the theme being used. Turning blocks on and off via the Admin Panel also makes the change ubiquitous across the site—no danger of a block or stray link accidently showing up on a little trafficked page you didn’t remember to change the code for—and you can reverse the process, turning the block back on whenever desired.

Header

image
Remove/Edit the Default welcome message
ADMIN: System → Configuration → Design tab → Header panel. Edit or delete the contents of the "Welcome Text" field.

Footer

image
 
Remove/edit the CMS-based links (About us | Customer Service)
ADMIN: CMS → Static Blocks. Disable or modify the "footer_links" block.
Remove Site Map link (and site map itself)
ADMIN: System→Configuration→Catalog tab→SEO panel. Set “Autogenerated Site Map” to "Disable."
Remove Popular Search Terms link (and search terms page)
ADMIN: System→Configuration→Catalog tab→SEO panel. Set “Popular Search Terms” to "Disable."
Remove Contact us link (and contact form)
ADMIN: System → Configuration → Contacts tab. Set "Enable Contact Us" field to "No."
Remove RSS link and functionality
ADMIN: System→Configuration→RSS Feeds tab→RSS Config panel. Set “Enable RSS” to "Disable."
Remove/edit the Copyright notice
ADMIN: System → Configuration → Design tab → Footer panel. Edit or delete the contents of the "Copyright" field.
Remove "Keep Magento healthy" message
This message is hard-coded in the current theme's template/page/html/footer.phtml file and can be edited there. As a temporary workaround, you can hide this message using CSS. Go to ADMIN: System → Configuration → Design tab → Footer panel. In the "Miscellaneous HTML" field insert the following CSS statement: <style>p.bugs {display: none;}</style>

Newsletter

image
Remove the sign up block and disable functionality
ADMIN: System → Configuration → Advanced tab. Set “Mage_Newsletter” to "Disable."

Poll

image
Disable all polls
ADMIN: System → Configuration → Advanced tab. Set “Mage_Poll” to "Disable."
Remove current poll but leave functionality available for later
ADMIN: CMS → Polls. Set “Status” of the current poll to “Closed”.

PayPal logo

image
Remove logo only (leave functionality available)
ADMIN: System → Configuration → PayPal tab → Frontend Experience panel. Set “PayPal Product Logo” to “No logo.”

Wishlist

image
Remove top link and disable functionlity
ADMIN: System → Configuration → Advanced tab. Set “Mage_Wishlist” to "Disable."

Reviews

image
Remove product page links and disable functionality
ADMIN: System → Configuration → Advanced tab. Set “Mage_Review” to "Disable."

Tags

image
Remove tag cloud and disable product page functionality
ADMIN: System → Configuration → Advanced tab. Set “Mage_Tag” to "Disable."

Cart Sidebar

image
Remove sidebar only (leave functionality available)
ADMIN: System → Configuration → Checkout tab → Shopping Cart Sidebar panel. Set “Display Shopping Cart Sidebar” to “No.”

Common Elements You Can Turn Off Via the Layout Files

Some Magento blocks are controlled by larger modules and cannot be turned on and off quite so neatly using just the Admin Panel. Instead, those blocks are best turned off using the layout (xml) files for your theme. Below is a list of some of these blocks for the default design package. You may have additional blocks in your design package and theme, but you can use this a guidance for determining where the blocks you're working with are likely to be declared. The section following this provides some instructions on how to do disable these blocks. As with using the Admin Panel, disabling a module at the layout level will ensure that it’s truly off across your entire site.

Header

image
Cart & Checkout links
Set in base/default/layout/checkout.xml
My Account, Log In & Log Out links
Set in base/default/layout/customer.xml

Left Callout banner (the dog)

image
Sidebar block
Set in base/default/layout/catalog.xml

Right Callout banner (back to school)

image
Sidebar block
Set in base/default/layout/catalog.xml

Compare Products sidebar

image
image
Sidebar block
Set in base/default/ layout/catalog.xml
Product and category page links
The “Add to compare” link on the product page is set in template/catalog/product/add-to.phtml and needs to be removed separately. As a temporary workaround, you can hide this message using CSS. Go to ADMIN: System → Configuration → Design tab → Footer panel. In the "Miscellaneous HTML" field insert the following CSS statement: <style>p.link-compare {display: none;}</style>

Cart

image
Sidebar block
Set in base/default/layout/checkout.xml
Top links--cart and checkout
Set in base/default/layout/checkout.xml

Recently Viewed Products sidebar

image
Sidebar block
Set in base/default/layout/report.xml

Recently Compared Products sidebar

image
Sidebar block
Set in base/default/layout/report.xml:

How to Disable Modules and Blocks in the Layout (xml) Files

First, do NOT edit the files in the base design package (base/default directory) even though most of the blocks are defined there. Any changes to the base design package will get overwritten whenever Magento is reinstalled or upgraded. Instead make a new directory for your custom theme and make your mods there.

→See this article for more information on Magento's Theme Hierarchy

Method 1: (recommended for CE v1.3- and EE v1.7-)

If you haven’t already, create a directory for your new theme, either as a theme inside of an existing design package or as a new design package.

Using the list in the previous section as a guide, find the xml files in your theme’s layout directory that contain the blocks you want to disable. In each applicable file, delete or comment out the block declarations for the blocks you want to remove.

If your theme is the default theme for your design package (e.g, in yourDesignPackage/default), it must contain all of the necessary layout files and you can modify and save them directly.

If your theme is a variant of the default theme for your design package (e.g., yourDesignPackage/yourTheme), copy and save only the files you have to change from yourDesignPackage/default/layout to your new theme variant at yourDesignPackage/yourTheme/layout.

→See this wiki post for a community-provided tutorial on this method: http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/0_-_theming_in_magento/package

Method 2: : (recommended for CE v1.4+ and EE v1.8+)

You can use Method 1 for the newest versions of Magento as well, but a more elegant and maintainable approach for turning blocks on and off in Magento CE v1.4+ and EE/PE v1.8+ is to create a layout file in your custom theme directory that overrides the behavior of only certain blocks in the base theme. You don’t need to copy over all the theme files and delete or comment out code in each. You can rely on the base theme to contain all the default blocks and in your theme you simply de-reference the blocks you don’t want. In addition, you can do this all in one place so that your changes are easier to keep track of.

This works because Magento CE v1.4+ and EE v1.8+ use a theme fall-back mechanism in which the application looks for each theme file or block declaration first in your custom theme package and then, if it doesn’t find it there, it looks for it in the base theme package. So your custom theme only needs to contain the files, or really just the blocks, that are different from the base theme.

For CE: In the app/design directory, create a new directory for your theme. If you are creating a new design package, you will create the following directory structure:

app/design/frontend/yourDesignPackage/default/layout/
If you are creating a new theme inside of the default design package, you will create the following directory structure:
app/design/frontend/default/yourTheme/layout/

If you’re creating a new design package, you will also need to copy or create CSS and image files for your theme to the skin directory if you haven’t already, but we’ll leave that for you to do on your own since it’s not related to turning on and off the blocks using the layout files.

For EE/PE: In Enterprise Edition, the Enterprise functionality is itself made available through a custom theme that modifies base, so in order to leverage all of the Enterprise functionality, you must either copy both the design and the skin directories from enterprise/default to a new design package directory or create your new theme inside of the Enterprise design package. Depending on which you do, you will be working into one of the following directories:

app/design/frontend/enterprise/yourTheme/layout
app/design/frontend/yourDesignPackage/yourTheme/layout

For both CE and EE/PE, once your design package and theme structure is set up as described above, inside of the layout directory, create a file called local.xml. Inside of local.xml, create a <default> block that will contain and consolidate your global changes:

<?xml version="1.0" ?>
<layout>
   <default>
      <!-- 
Your block overrides will go here -->
   </default>
</
layout>

Depending on what you want to turn off, local.xml might contain some of the following lines.

<default>
   <
remove name="left.permanent.callout" />  <!--the dog-->
   <
remove name="right.permanent.callout" />  <!--back to school-->
   <
remove name="catalog.compare.sidebar" />  <!--product compare-->
   <
remove name="paypal.partner.right.logo" />  <!--paypal logo-->
   <
remove name="cart_sidebar" /> <!--cart sidebar-->
   <
remove name="left.reports.product.viewed" /> <!--recently viewed prod-->
   <
remove name="right.reports.product.viewed" /> <!--recently viewed prod-->
   <
remove name="right.reports.product.compared" /> <!--recently compared prod-->
</default>

This will vary depending on the theme so this is only guidance. Use the list in the previous section as a guide, find the xml file in your theme’s layout directory (or the base layout directory) that contains the block(s) you want to disable and find the names of the blocks in that file. You can then use those names in your local.xml file to remove the blocks. Also, the example above removes content blocks from the default scope, you may prefer to remove them only from specific structural blocks--like "left" or "right." But this gives you an idea of how it works and we'll cover more examples of that in a later article.

→See this wiki post for a community-provided tutorial on this method: http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/0_-_theming_in_magento/designing-for-magento

How to Tell Magento to Use Your Custom Theme

To get Magento to use your new custom theme, go to ADMIN: System → Configuration → Design tab. In the Package panel, set the “Current Package Name” field to whatever your design package name is: yourDesignPackage, default or enterprise. Then in the Theme panel, set the “Default” field to whatever your theme name is: default or yourTheme. Save it and refresh the frontend to see your changes.

If you did not copy or create CSS files, if you reload the frontend right now, it’ll look terrible (unstyled basically) because the base package does not have CSS for styling the website. So be sure to copy or create your CSS and image directories as well.

Where to Next?

In this article, we illustrated how to disable Magento blocks using the Admin Panel. We’ve also just scratched the surface on using a local.xml file to override the layouts for just the blocks we wanted to disable, rather than copying files and deleting code. Using this same approach, you can also add blocks, change where they appear, change some of their behavior, etc. just by overriding the default behavior in a single location and never editing the actual layout files. Later articles will go into more detail and provide more examples of how to do this, but hopefully this is enough to get you started and exploring another way to customize your Magento themes.

类别 :  magento(258)  |  浏览(3504)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: