如何在 Magento 布局中向侧边栏 div 添加类?

发布于 2024-10-19 20:05:06 字数 270 浏览 3 评论 0原文

如何将类添加到 Magento 布局中的 div 中?我只想在我的一个页面上更改它。默认情况下,我有:

<div class="col-left sidebar">

我想要:

<div class="col-left sidebar my-class">

我无法在 2-columns-left 中更改此设置,因为它会在 Magento 的所有页面上更改。是否可以?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜无邪 2024-10-26 20:05:06

如果您只想更改一页,可以尝试复制 2-columns-left 模板,重命名并编辑它,然后编辑页面以使用新模板。

  1. 重命名并编辑 2-columns-left.phtml 文件。这可以在 /app/design/frontend/default/YOUR_THEME/template/page 中找到。在第 50 行左右,您将看到

  2. 编辑 config.xml 文件以便页面使用新模板。 Config.xml 位于 /app/code/core/Mage/Page/etc 中。大约中间,您会看到引用two_columns_left的代码;复制此代码,然后编辑它以指向新页面。

  3. 最后通过后台编辑页面>内容管理系统页面使用新的模板。您现在可以通过主题中的 CSS 添加样式。

更多说明

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.

  1. 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.

  2. 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.

  3. 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.

当梦初醒 2024-10-26 20:05:06

方法 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> 

您可以在此处添加 javascript 和 css。请注意,您添加的任何 Js 文件都相对于根目录中的“js”文件夹。 css 文件包含在当前和默认模板的外观文件 (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> 

还可以在管理后端的布局 XML 区域(CMS 页面、类别和产品设计)中使用。这可以完成同样的事情,以及添加或删除其他块。

方法 2 - 块代码:

我们也可以在代码中完成所有这些。这些函数在 Mage_Page_Block_Html_Head 中定义。因此,我们可以在块类中使用此代码(不是 .phtml 文件!):

$headBlock = $this->getLayout()->getBlock('head');
$headBlock->addJs('somefolder/yay.js'); 

我建议查看 page.xml 文件,只要找到removeItem 语法($type, $name 为方法,为 xml ),这对于您在需要时添加或删除资产非常方便!

<action method="removeItem"><type>js</type><name>calendar/calendar.js</name</action>
$this->getLayout->getBlock('head')->removeItem('js', 'calendar/calendar.js'); 

文章发布:http://www.exploremagento .com/magento/adding-and-remove-js-css.php

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文