4

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 Answers 2

3

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!

3
  • 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?! Nov 10, 2017 at 12:39
  • Try with updated code Nov 10, 2017 at 12:42
  • The new one, moved title of page in bottom of products list. not Breadcrumbs! Nov 10, 2017 at 12:44
1

Here I achieved this line by using below line, If you have the same requirement you can use this line of code.

<move element="breadcrumbs" destination="main.content" before="-"/>

I hope it may help you. find the reference image below.

enter image description here

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.