0

Edit: Could not having crontab and cron set up affect compiling the layout files and be related at all to the custom layout not loading? I have since moved all my logic out of the app/design/frontend/Vendor/default theme folders and moved them into my own separate custom module and it is still working perfectly locally but not working on staging, with no errors visible. Can anyone advise?

I have been working with Magento 2 for nearly 2 years and am very used to extending templates by creating files in app/design/Vendor/default/Magento_Module/layout folders, and using this to add custom blocks and inserting custom templates and overriding default templates.

I have a project I am working on currently and I have a local instance and a staging instance. On my local, I wanted to extend the CatalogSearch/Block/Result template to add some elements to the page (displaying page search results alongside product search results). So I used catalogsearch_result_index.xml to overwrite the template and add my own block. My catalogsearch_result_index.xml file looks like this:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <attribute name="class" value="page-products"/>
        <referenceContainer name="content">
            <block class="Vendor\Search\Block\SearchResult" name="search.result" template="Magento_CatalogSearch::result.phtml">
                <block class="Magento\CatalogSearch\Block\SearchResult\ListProduct" name="search_result_list" template="Magento_Catalog::product/list.phtml">
                    <arguments>
                        <!-- If argument's position depends on image size changeable in VDE:
                        positions:list-secondary,grid-secondary,list-actions,grid-actions,list-primary,grid-primary
                    -->
                        <argument name="positioned" xsi:type="string">positions:list-secondary</argument>
                    </arguments>
                    <block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
                        <block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
                    </block>
                    <action method="setToolbarBlockName">
                        <argument name="name" xsi:type="string">product_list_toolbar</argument>
                    </action>
                    <block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
                        <block class="Magento\Framework\View\Element\Template" name="category.product.type.details.renderers.default" as="default"/>
                    </block>
                    <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="catalogsearch.product.addto" as="addto">
                        <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
                               name="catalogsearch.product.addto.compare" as="compare"
                               template="Magento_Catalog::product/list/addto/compare.phtml"/>
                    </block>
                </block>
                <action method="setListOrders"/>
                <action method="setListModes"/>
                <action method="setListCollection"/>
            </block>
            <block class="Magento\Framework\View\Element\Template" name="search.search_terms_log" template="Magento_CatalogSearch::search_terms_log.phtml">
                <arguments>
                    <argument name="search_terms_log" xsi:type="object">Magento\CatalogSearch\Block\SearchTermsLog</argument>
                </arguments>
           </block>
       </referenceContainer>
   </body>
</page>

I added my logic in my custom Block's SearchResult.php file, and I created a new result.phtml inside the following folder: app/design/frontend/Vendor/default/Magento_CatalogSearch/result.phtml.

It works beautifully locally. My logic from the block gets the right data and it is displaying in the template coming from my extended result.phtml. However, when I push my code up to the staging site, for some reason the template content just doesn't show at all... it's simply blank. It doesn't throw any errors.

I have tried running setup:upgrade, setup:di:compile, cleared and flushed cache a bunch of times, tried clearing var/cache/*, tried reindexing, and none of this has made a difference. I keep checking in the var/log folder for any errors and it doesn't show any.

I tried going into the staging site and deleting my result.phtml file so it falls back on the core Magento result.phtml file but it is still blank. I tried changing the catalogsearch_result_index.xml file to use the default Magento\CatalogSearch\Block\Result file instead of my custom module file and it's still blank (and doesn't throw errors even when it should be as I am calling custom functions in my result.phtml file).

I tried turning on template hints and it looks like the result.phtml template is not even being added to the page. If I leave my custom block on the layout xml file and change the template to some generic file like result2.phtml (with the only content being: <div class="test">This is loading</div>) then that content and the template loads. This leads me to thinking that it's not an error with my block class, nor an error with my layout.xml class. So then I'm thinking it might be an issue with my template itself?

If I change my dummy template from the above text div to something with php that is calling a function from my custom block: This is loading getResultCount(); ?> and then flush cache the php doesn't show, only the text. I have also tried just echoing a php string there so it isn't pulling from my custom block, and that doesn't show either (just the string of text above). So then is it some kind of hardcore caching issue? Or is there some reason that all the php in my file is being hidden/stripped out?

Even if the php is somehow not being loaded for the given template, you would think that the template would always be loaded when viewing the page with template hints. Or does it not load a blank template by default?

If I try then to switch it back to my custom result.phtml template and add the same generic div text at the top of the file (to get it to load if nothing else), and clear cache, this doesn't show and template hints say that template isn't even being loaded.

What else can I try? I cannot reproduce at all locally and am at a total loss. I have tried to make it deliberately throw errors and it doesn't seem to be doing it. What else can I test?

Sidenote: I just tried changing my layout xml file's block to be the generic Magento\Framework\View\Element\Template, and in that case it does load from the correct result.phtml file. Can I not extend a class that is already extending the template class (can it not extend 2 levels deep)? I will be testing trying to override the class I need rather than extending to see if that makes a difference.

Any help is urgently needed and welcome.

0

Please run setup:static-content:deploy command and check.

The static view files deployment command enables you to write static files to the Magento file system when the Magento software is set for production mode.

| improve this answer | |
  • I have tried this multiple times to no avail. Any other suggestions welcome. – Erica Summers Mar 13 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.