简体   繁体   English

Magento catalogsearch.xml中的自定义块

[英]Custom Block in Magento catalogsearch.xml

I have created a sample module Web. 我创建了一个示例模块Web。 Also I have created one Sample Block for this. 我也为此创建了一个示例块。 I have one web.phtml file in app/design/frontend/default/default/template folder and one web.xml file in app/desing/fronted/default/default/layout file. 我在app / design / frontend / default / default / template文件夹中有一个web.phtml文件,在app / desing / fronted / default / default / layout文件中有一个web.xml文件。 Below is my web.xml file 以下是我的web.xml文件

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
    </default>
    <web_index_index>
    <reference name="root">
          <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
    </reference>
        <reference name="content">
            <block type="web/web" name="web" template="web/web.phtml" />
        </reference>
    </web_index_index>
</layout> 

It works properly in my http://mydomain.com/magento/web . 它可以在我的http://mydomain.com/magento/web中正常运行。

Now I copied a catalogsearch.xml file from app/desing/fronted/base/default/layout and paste it in app/desing/fronted/default/default/layout and added block code in it after results.phtml but I am not able to see the block in my catalogsearch page. 现在,我从app / desing / fronted / base / default / layout复制了catalogsearch.xml文件,并将其粘贴到app / desing / fronted / default / default / layout中,并在results.phtml之后添加了块代码,但是我无法在我的目录搜索页面中查看该块。

<block type="web/web" name="web" template="web/web.phtml" /> 

What I am missing here? 我在这里想念的是什么? What is the proper way to add block in catalogsearch.xml file? 在catalogsearch.xml文件中添加块的正确方法是什么?

The file in which a layout update directive appears is (generally) irrelevant. 出现布局更新指令的文件(通常)是不相关的。 What scopes layout XML directives are the layout update handles. 布局更新句柄是什么范围的布局XML伪指令。

For catalogsearch results you will want to add your block to two handles if you want it in both the simple and advanced search results views; 对于catalogsearch结果,如果希望在简单和高级搜索结果视图中都将其添加到两个句柄中,则将其添加到两个句柄中。 add this to your web.xml layout file: 将此添加到您的web.xml布局文件中:

<catalogsearch_result_index>
    <reference name="content">
        <block type="web/web" name="web" template="web/web.phtml" after="-" /> 
    </reference>
</catalogsearch_result_index>

<catalogsearch_advanced_result>
    <reference name="content">
        <block type="web/web" name="web" template="web/web.phtml" after="-" /> 
    </reference>
</catalogsearch_advanced_result>

Now, most developers will blanche at the thought of repeating code. 现在,大多数开发人员都会对重复代码一无所知。 The above instruction can be written once in a utility handle and then the utility handle can be used to apply the result elsewhere: 上面的指令可以在实用程序句柄中编写一次,然后可以使用该实用程序句柄将结果应用于其他地方:

<web_addToContent>
    <reference name="content">
        <block type="web/web" name="web" template="web/web.phtml" after="-" /> 
    </reference>
</web_addToContent>

<catalogsearch_advanced_result>
    <update handle="web_addToContent" />
</catalogsearch_advanced_result>

<catalogsearch_advanced_result>
    <update handle="web_addToContent" />
</catalogsearch_advanced_result>

If the block is appearing at the beginning of the content (despite after="-" ), it may be necessary to make the web module's config XML load after the catalog search module. 如果该块出现在内容的开头(尽管after="-" ),则可能有必要在目录搜索模块之后加载Web模块的配置XML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM