0

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

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

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

那行得通,主页正在使用我的模板,但 Magento 没有将任何 css 文件导入页面的 head 部分。甚至没有像styles.css 这样的默认值。我尝试使用上面的 xml 更新并使用 local.xml 和引用 head 添加我自己的,但没有任何效果。

有任何想法吗?谢谢你的建议。

4

2 回答 2

1

You have a problem with the change of the template. From the phtml file you need made the $this->getChildHtml() corresponding. If you go to your old template in app/design/frontend/base/page/3colums.phtml for example you can see the next command lines:

 <!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>

Ok, then you be careful with this, all block in yout template need a getChildHtml() from the corespondig phtml. In your case is probably that you don´t add this call from the template. Then don´t work head, content, footer, etc. I think this is your ploblem, nonetheless you can write the content of your custom template to help you with the solution. Hope help you

于 2012-06-12T19:51:52.737 回答
0

要获得 Magento CSS 和 js,您需要拥有

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

在你<head>的标签里面,这样它就可以从 page.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。也应该在你的包/主题的 page.xml 下添加你的 CSS

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

并确保您在主题的 css 文件夹中有该文件

于 2012-06-13T17:22:42.520 回答