1

I have this file

app\design\frontend\company\mytheme\web\templates\header\foobar.phtml

How can I reference it in a layout file e.g. in

app\design\frontend\company\mytheme\Magento_Theme\layout\default.xml

e.g. to set it as a template for a block?

<referenceContainer name="header.container">
    <container name="header-wrapper" label="Page Header" as="header-wrapper" htmlTag="div" htmlClass="header content foobar">
        <block class="Magento\Theme\Block\Html\Header\Logo"
               name="logo" 
               template="Magento_Theme::foobar.phtml"  <-- this does not work... how to make it right and set foobar.phtml as template ?
        >
            <arguments>
                <argument name="logo_img_width" xsi:type="number">189</argument>
                <argument name="logo_img_height" xsi:type="number">64</argument>
            </arguments>
        </block>
    </container>
</referenceContainer>

If I move foobar.phtml to app\design\frontend\company\mytheme\Magento_Theme\templates then it works, but how does it work from my themes web directory?

1 Answer 1

0

I solved it by creating a new folder named Company_Mytheme (Vendor_Themename) and moving foobar.phtml to

app\design\frontend\company\mytheme\Company_Mytheme\templates\foobar.phtml

Then I referenced it like this:

<referenceContainer name="header.container">
    <container name="header-wrapper" label="Page Header" as="header-wrapper" htmlTag="div" htmlClass="header content foobar">
        <block class="Magento\Theme\Block\Html\Header\Logo"
               name="logo" 
               template="Company_Mytheme::foobar.phtml"
        >
            <arguments>
                <argument name="logo_img_width" xsi:type="number">189</argument>
                <argument name="logo_img_height" xsi:type="number">64</argument>
            </arguments>
        </block>
    </container>
</referenceContainer>

You can name the folder anything you like, e.g. Foo_Bar, it will also work, you just have to make sure to use it in the layout

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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