confused about adding a layout update in my new mo

2019-08-02 20:49发布

问题:

I need a special script to be rendered on the head tag on the success page.

I created this file luisvalenciaaffiliatecj.xml path: /app/design/frontend/base/default/layout/luisvalenciaaffiliatecj.xml

<?xml version="1.0"?>
<layout version="0.0.1">
    <checkout_onepage_success>
        <reference name="head">
            <block type="core/template" name="cj_udo" template="cj/udo.phtml" />
        </reference>
    </checkout_onepage_success>
</layout>

My config.xml (see layout updates section)

this is the folder structure under community http://screencast.com/t/WGEobN5ocjJE

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Luisvalencia_Affiliate>
            <version>0.0.1</version>
        </Luisvalencia_Affiliate>
    </modules>
    <layout>
        <updates>
            <luisvalencia_affiliate>
                <file>luisvalenciaaffiliate.xml</file>
            </luisvalencia_affiliate>
        </updates>
    </layout>
    <global>
        <models>
            <luisvalencia_affiliate>
                <class>Luisvalencia_Affiliate_Model</class>
            </luisvalencia_affiliate>
        </models>
        <helpers>
            <affiliate>
                <class>Luisvalencia_Affiliate_Helper</class>
            </affiliate>
        </helpers>
    </global>
    <frontend>
        <events>
            <controller_action_predispatch>
                <observers>
                    <luisvalencia_affiliate>
                        <class>luisvalencia_affiliate/observer</class>
                        <method>captureReferral</method>
                        <type>singleton</type>
                    </luisvalencia_affiliate>
                </observers>
            </controller_action_predispatch>
        </events>
    </frontend>
</config>

I dont see any errors on the logs, but the code is not being executed because I cant see the tag that I should render on the head tag.

回答1:

<layout> section should be under <frontend>. So your config.xml should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Luisvalencia_Affiliate>
            <version>0.0.1</version>
        </Luisvalencia_Affiliate>
    </modules>
    <global>
        <models>
            <luisvalencia_affiliate>
                <class>Luisvalencia_Affiliate_Model</class>
            </luisvalencia_affiliate>
        </models>
        <helpers>
            <affiliate>
                <class>Luisvalencia_Affiliate_Helper</class>
            </affiliate>
        </helpers>
    </global>
    <frontend>
        <layout>
            <updates>
                <luisvalencia_affiliate>
                    <file>luisvalenciaaffiliate.xml</file>
                </luisvalencia_affiliate>
            </updates>
        </layout>
        <events>
            <controller_action_predispatch>
                <observers>
                    <luisvalencia_affiliate>
                        <class>luisvalencia_affiliate/observer</class>
                        <method>captureReferral</method>
                        <type>singleton</type>
                    </luisvalencia_affiliate>
                </observers>
            </controller_action_predispatch>
        </events>
    </frontend>
</config>

Add this code in echo $this->getChildHtml('cj_udo'); in head.phtml



标签: php magento