6

私の Magento Commerce テーマから取得した次のコードに従ってください。

layout/page.xml から抽出

<block type="page/html_header" name="header" as="header">
    <block type="page/template_links" name="top.links" as="topLinks"/>
    <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
    <block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
    <block type="directory/currency" name="store_currency_selector" as="store_currency_selector" template="directory/currency_top.phtml"/>
    <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
        <label>Navigation Bar</label>
        <block type="page/template_links" name="top.links.mobile" as="topLinksMobile"/>
        <block type="checkout/cart_sidebar" name="cart_sidebar_mobile" as="cartSidebarMobile" template="checkout/cart/topbar.phtml"/>
    </block>
    <block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
        <label>Page Header</label>
        <action method="setElementClass"><value>top-container</value></action>
    </block>
    <block type="checkout/cart_sidebar" name="cart_sidebar" as="topcart" template="checkout/cart/topbar.phtml"/>
</block>

template/catalog/navigation/top.phtml から抽出

<li class="level0 nav-2 active level-top first parent">
    <a href="javascript:;">ACCOUNT</a>
    <?php echo $this->getParentBlock()->getChildHtml('topLinksMobile'); ?>
</li>
<li class="level0 nav-3 active level-top first parent">
    <a href="javascript:;">CART</a>
    <?php echo $this->getChildHtml('cartSidebarMobile'); ?>
</li>

基本的に、私がやろうとしているのは、「topMenu」ブロック内に 2 つのサブブロックを作成し、「getChildHtml」関数を使用してそれらをテンプレートに出力することです。

残念ながら、top.phtml がコンテンツを生成する前に 2 つのブロックが読み込まれている間、関数呼び出しは失敗します。

私が間違っていることについて何かアドバイスをください。

よろしくお願いします。

4

3 に答える 3

0

次のファイルで関数を呼び出してみてください template/page/html/topmenu.phtml

于 2013-05-17T07:47:51.227 に答える
0

少し進んだ。

読むことによって: Magento - ブロックを表示しますが、getChildHtml で呼び出したときにのみ表示されます

および: Magento ブロックとブロック タイプについて

core/text_list が自動的にコンテンツを出力することがわかったので、タイプを「page/html_wrapper」に変更しました。

問題は、これら 2 つの要素の内容が重複していることです。1 回目は top.phtml のコンテンツの前、2 回目は getChildHtml が呼び出されたときです。

どんなアイデアでも大歓迎です。

于 2013-05-17T09:30:55.590 に答える