无法在Magento中添加css


Can't add css in Magento

将我的主页的自定义模板放置在mytheme/layout/page/customhome.phtml中

要将其应用于主页,我必须将管理员 CMS 用作本地.xml无法更改主页的模板。我使用此代码在自定义布局更新 xml 框中执行此操作:

 <reference name="root">
     <action method="setTemplate">
        <template>page/homes.phtml</template>
    </action>
</reference>

这有效,主页正在使用我的模板,但 Magento 没有将任何 css 文件导入页面的头部部分。甚至不是像样式这样的默认.css。我尝试使用上面的xml更新添加自己的xml更新,并使用本地.xml和引用头,但没有任何效果。

有什么想法吗?谢谢你的建议。

您对模板的更改有问题。从 phtml 文件中,您需要使 $this->getChildHtml() 对应。例如,如果您在app/design/frontend/base/page/3colums.phtml中转到旧模板,则可以看到下一个命令行:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
<?php echo $this->getChildHtml('after_body_start') ?>
<div class="wrapper">
    <?php echo $this->getChildHtml('global_notices') ?>
    <div class="page">
        <?php echo $this->getChildHtml('header') ?>
        <div class="main-container col3-layout">
            <div class="main">
                <?php echo $this->getChildHtml('breadcrumbs') ?>
                <div class="col-wrapper">
                    <div class="col-main">
                        <?php echo $this->getChildHtml('global_messages') ?>
                        <?php echo $this->getChildHtml('content') ?>
                    </div>
                    <div class="col-left sidebar"><?php echo $this->getChildHtml('left') ?></div>
                </div>
                <div class="col-right sidebar"><?php echo $this->getChildHtml('right') ?></div>
            </div>
        </div>
        <?php echo $this->getChildHtml('footer') ?>
        <?php echo $this->getChildHtml('before_body_end') ?>
    </div>
</div>
<?php echo $this->getAbsoluteFooter() ?>
</body>
</html>

好的,那么你要小心这一点,你t模板中的所有块都需要一个来自corespondig phtml的getChildHtml()。在您的情况下,您可能没有从模板添加此调用。然后不要工作头部、内容、页脚等。我认为这是您的问题,但是您可以编写自定义模板的内容来帮助您解决问题。希望对您有所帮助

要获得Magento CSS和js,你需要有

<?php echo $this->getChildHtml('head') ?>

在你里面<head>标签,以便它会去从页面获取它们.xml

<block type="page/html_head" name="head" as="head">
                <action method="addJs"><script>prototype/prototype.js</script></action>
                <action method="addJs"><script>lib/ccard.js</script></action>
                <action method="addJs"><script>prototype/validation.js</script></action>
                <action method="addJs"><script>scriptaculous/builder.js</script></action>
                <action method="addJs"><script>scriptaculous/effects.js</script></action>
                <action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
                <action method="addJs"><script>scriptaculous/controls.js</script></action>
                <action method="addJs"><script>scriptaculous/slider.js</script></action>
                <action method="addJs"><script>varien/js.js</script></action>
                <action method="addJs"><script>varien/form.js</script></action>
                <action method="addJs"><script>varien/menu.js</script></action>
                <action method="addJs"><script>mage/translate.js</script></action>
                <action method="addJs"><script>mage/cookies.js</script></action>
                <block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
                <action method="addCss"><stylesheet>css/styles.css</stylesheet></action>
                <action method="addItem"><type>skin_css</type><name>css/styles-ie.css</name><params/><if>lt IE 8</if></action>
                <action method="addCss"><stylesheet>css/widgets.css</stylesheet></action>
                <action method="addCss"><stylesheet>css/print.css</stylesheet><params>media="print"</params></action>
                <action method="addItem"><type>js</type><name>lib/ds-sleight.js</name><params/><if>lt IE 7</if></action>
                <action method="addItem"><type>skin_js</type><name>js/ie6.js</name><params/><if>lt IE 7</if></action>
            </block> 

一旦你有了这个,你应该得到Magento需要的CSS和js。 也应该在您的包/主题页面下添加您的 CSS.xml通过

<action method="addCss"><stylesheet>css/customs.css</stylesheet></action>

并确保该文件位于主题的 CSS 文件夹中