3

I want to move page.main.title block to my breadcrumbs container, not before or after it, I want to push it inside breadcrumbs template and remove other wheres.

So this is my ~/Magento_Theme/templates/html/header/breadcrumbs.phtml :

<div class="container">
    <div class="breadcrumbs">
        <span class="current-name">
            <?php
                 /*** I NEED PAGE.MAIN.TITLE BLOCK HERE ***/
            ?>
        </span>
        <ul class="items">
            <?php /* showing breadcrumb items */ ?>
        </ul>
    </div>
</div>

in above template in .current-name class I need the title block!

I did this in ~/Magento_Theme/layout/default.xml, but it goes before breadcrumbs block not inside it:

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <move element="page.main.title" destination="page.top" before="breadcrumbs"/>
        <referenceContainer name="page.top">
            <block class="Magento\Theme\Block\Html\Breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>
        </referenceContainer>
    </body>
</page>

and I did this in breadcrumbs.phtml too, It works perfectly but the Title exists in other wheres and I have 2 <h1> tag in my page, so that is wrong!:

echo $block->getBlockHtml('page.main.title');

and I want to use this block(page.main.title) for showing my title Because of SEO stuff and I think this is the proper way! not the bad ways like show title from latest crumb label in loop or anything like that!

Note that the '~' character above is pointing my theme folder (app/design/frontend/MyVendor/myTheme).

Note that I'm using Magento 2.1.9 with PHP 7.0.24.

2

Try with below way,

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <move element="page.main.title" destination="breadcrumbs" before="-" />
    </body>
</page>

Edit:

Then you need to use echo $block->getChildHtml('page.main.title'); in everywhere of your breadcrumbs.phtml file.

But I don't know better way to do that!

  • 1
    After use your code, every titles disappeared! it worked like remove="true" in layout xml. But after that using echo $block->getChildHtml('page.main.title');, It worked. and show title in there. but is this a proper way?! – Mehran Zarei Nov 10 '17 at 12:39
  • Try with updated code – Rakesh Jesadiya Nov 10 '17 at 12:42
  • The new one, moved title of page in bottom of products list. not Breadcrumbs! – Mehran Zarei Nov 10 '17 at 12:44

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.