как правильно вызвать файл phtml на странице успеха?


У меня есть шаблон в template/checkout/onepage/hello.phtml

Я хочу включить этот файл phtml на страницу успеха, т.е. template/checkout/success.phtml

Поэтому я создал блок в checkout.xml внутри дескриптора "checkout_onepage_success" как:

<checkout_onepage_success translate="label">
    <label>One Page Checkout Success</label>
    <reference name="root">
        <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
    </reference>
    <reference name="content">
         <block type="core/template" name="onepagehello" template="checkout/onepage/hello.phtml"/>
        <block type="checkout/onepage_success" name="checkout.success" template="checkout/success.phtml"/>
    </reference>
</checkout_onepage_success>  

И этот файл phtml отображается на странице успеха в верхней части страницы.

Когда я пишу getChildHtml(onepagehello); на странице success.phtml, ничего не приходит.

  1. Я хочу знать, когда getChildHtml() работает и когда блок визуализируется?
  2. Я хочу получить "hello.phtml" от getChildHtml(), чтобы я мог разместить этот блок везде, где это необходимо, по всей странице.
Author: Fabian Schmengler, 2016-01-18

2 answers

Макет представляет собой иерархию блоков, и getChildHtml() может отображать только дочерние элементы текущего блока.

Прямо сейчас ваша иерархия выглядит так:

root
+-- content
    +-- onepagehello
    +-- checkout.success

Но вам нужно это:

root
+-- content
    +-- checkout.success
        +-- onepagehello

Чтобы добавить новый блок в существующий родительский блок, используйте <reference>:

<checkout_onepage_success>
    <reference name="checkout.success">
         <block type="core/template" name="onepagehello" template="checkout/onepage/hello.phtml"/>
    </reference>
</checkout_onepage_success>  
 6
Author: Fabian Schmengler, 2016-01-18 11:38:18

Просто добавьте элемент как="ИМЯ" в свой блок вот так

<block type="core/template" name="onepagehello" template="checkout/onepage/hello.phtml" as="hello"/>

Вы можете позвонить так

getChildHtml('hello');
 3
Author: Hitesh Vaghasiya, 2016-01-18 12:05:28