2

I having a problem inserting a block after magento header logo. I want to know how it's done in my default.xml.

Currently this is my code:

    <referenceContainer name="top.search">
        <block class="Crystal\Customblocks\Block\Cti"  template="default/cti.phtml" after="header.links"/>
    </referenceContainer>
3

A few years late, but to all those trying to do this in 2018:

<referenceContainer name="header-wrapper">
    <block class="Magento\Framework\View\Element\Template" name="linkboxes"  template="Magento_Theme::phtmlfileyouwant.phtml" after="logo"/>
</referenceContainer>

I find if you just want a Magento CMS block, try something like below inside the PHTML file.

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('[BLOCK ID]')->toHtml() ?>

However I generally don't reference a CMS block I just put whatever I'd put in the block in the PHTML file. I find this gives me more control over what I'm doing, (for instance allowing me to insert my own PHP script checking for cookies when the PHTML file loads, allowing me to then alter what my PHTML says as a result of the cookie check)

| improve this answer | |
  • Call me lazy or bad practice Why is this considered bad practise? – Frank Groot May 16 '18 at 14:35
  • 1
    when i wrote this comment I was very new to the community @FrankGroot I had previously seen a post about why referencing object manager was bad and believed that the getLayout function came from the object manager, again, i don't know why, good spot i'll make a revision – John May 16 '18 at 15:04
1

Please try below xml code:

 <referenceContainer name="header.container">
    <container name="header-wrapper" label="Page Header" as="header-wrapper" htmlTag="div" htmlClass="header content">
            <block class="Magento\Framework\View\Element\Template" name="your_file_name" template="Magento_Theme::html/your_file.phtml" after="logo"/>
            </container>
</referenceContainer>
| improve this answer | |
0

Try this it will work

<referenceContainer name="header-wrapper">
    <block class="Crystal\Customblocks\Block\Cti"  template="vendorName_moduleName::default/cti.phtml" after="logo"/>
</referenceContainer>

you can move elements back and forth from logo using after and before keyword

detailed of how to move elements or positioning new elements, refer this link

note: still I am not tested but I hope it will work

| improve this answer | |
  • Thanks man. I'll try this one. I will let you know if it work – MazeStricks Jun 29 '16 at 5:08
  • Ahmm I forgot to mention, I'm using porto theme for magento 2. I tried your codes man but it did not work. Thank you – MazeStricks Jun 29 '16 at 5:13
-1
<referenceContainer name="header-wrapper">
    <block class="Crystal\Customblocks\Block\Cti"  template="default/cti.phtml" after="logo"/>
</referenceContainer>

replace current code with this

| improve this answer | |

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.