in my theme, I need to display either "in stock" or "out of stock" in detail page. it's shown by default. I needed to display it right after the title. in one line. I moved in stock inside title block. but the problem is, There is a <h1> tag inside the title.phtml file and I need in stock to be <span> inside that `'. I can't move further in XML. Can't edit title.phtml to put span because when I do, it will affect for the every title instances inside my project.

How can I put a span inside h1 tag and instruct it to only display when on a product view?

1 Answer 1


You could create a new template (for example product_title.phtml) and only change the template in the catalog_product_view.xml of your module or theme:

<referenceBlock name="page.main.title">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">path/to/product_title.phtml</argument>

This way only the title template for that specific page is changed and you can still just put your <span> in there.

  • Hi, how do I set the path? is it something like, "Magento_Catalog/templates/products/view/view_title.phtml" or should I use just /products/view/filename.phtml?
    – Joey
    Sep 18, 2017 at 7:26
  • It depends, if you put it in the Magento_Catalog/templates-folder of your design, then just use the relative path. For example: products/view/view_title.phtml. If your template is provided by another module (for example, your own module) then you should prefix it. For example: Vendor_Module::products/view/view_title.phtml. Sep 18, 2017 at 7:30
  • Something like this? <referenceBlock name="page.main.title"> <action method="setTemplate"> <argument name="template" xsi:type="string">products/view/view_title.phtml</argument> </action> </referenceBlock> just the relative path right? no need to put module name and other path elements? (if im working with current module in this question its catalog)
    – Joey
    Sep 18, 2017 at 7:32
  • With this setup you have to put your template in app/design/frontend/[PACKAGE]/[THEME]/Magento_Catalog/templates/products/view/view_title.phtml. Sep 18, 2017 at 7:36

Your Answer

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

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