MagentoのレイアウトXMLに条件付きで(管理パネルの設定に応じて)ブロックを追加する方法は?
configがアクションに対して真であるかどうかを確認できます。以下の例でsample/config/show_toplinksは、管理パネル(System-> Configuration)の設定がtrueの場合、テンプレートファイルlinks.phtmlがトップリンクのレンダリングに使用されます。sample/config/show_toplinksがfalseの場合、デフォルトのテンプレートが使用されます。
<reference name="top.links">
    <action method="setTemplate" ifconfig="sample/config/show_toplinks">
        <template>page/template/links.phtml</template>
    </action>
</reference>この回避策はWebのどこかにありました。次のように、空のテンプレートをトップリンクのデフォルトテンプレートとして設定できます。
<reference name="top.links">
    <action method="setTemplate" ifconfig="sample/config/show_toplinks">
        <template>page/template/links.phtml</template>
    </action>
    <!-- OR set completely empty template -->
    <action method="setTemplate">
        <template>page/template/empty_template_for_links.phtml</template>
    </action>
</reference>この場合、sample/config/show_toplinksがtrueの場合、テンプレートlinks.phtmlが使用され、トップリンクが表示されます。しかし、場合sample/config/show_toplinksではfalse、その後、empty_template_for_links.phtmlテンプレートが使用され、それが任意のHTMLを返さないとトップリンクが表示されませんので、そのテンプレートは、完全に空です。
- 管理パネルの構成に応じて、条件付きでブロックを表示または非表示にする他の方法はありますか?
- この回避策は安全ですか?
- これにより、予期しないエラーが発生する可能性がありますか?
編集:
すべての回答に基づいて、Rick Kuipersのソリューションが私の場合に最も便利に見えると思います。しかし、別の関連する質問があります:
    <block type="core/template" name="my_block" template="my/block.phtml" />
    <!-- ...add more blocks here -->
    <reference name="footer">
        <action method="append" ifconfig="sample/config/show_toplinks">
            <block>my_block</block>
        </action>
        <!-- ...append more blocks here -->
    </reference>このように(appendメソッドとを使用してifconfig)追加するブロックが多数ある場合、50としましょう
 。パフォーマンスに影響しますか?一部のブロックのみが実際に表示されます(これは、システム->構成でのユーザーの設定に依存します)が、条件付きでブロックを追加する前に、それらすべてのブロックを追加する必要があります<reference name="footer">...</reference>。
Magentoは、このように追加されたすべてのブロックを即座に処理しますか?
    <block type="core/template" name="my_block" template="my/block.phtml" />またはブロックは、テンプレートに最終的に表示する必要がある場合にのみ処理されますか?それで、Magentoは表示する必要があるのは一部のブロックだけであるにもかかわらず、私の50ブロックすべてを処理する必要がありますか?