0

I want a custom home page. Design with layout "Empty" or a new layout created by me.

The only magento 2.1 standard block I want on this home page is the languages picker.

    <block class="vendor/magento/module-store/view/frontend/templates/switch" name="languages" template="languages.phtml"/>

I tired by creating my own layout file.

The problem is that this includes the "logo", "search entire store" and "shopping card" blocks/items and I only want the top bar with the language picker.

Any help would be greatly appreciated.

0

If I understand your question correctly, you want to strip the logo, search bar and shopping card from the block that contains the language switcher so you can use that block anywhere you want?

In your layout file (in my situation it's default.xml) I called the block named store_switcher instead of language and placed it in the footer.

<referenceContainer name="footer">
    <block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" after="footer_links" template="switch/stores.phtml"/>
</referenceContainer>

It doesn't contain the logo, search box etc.

Hope it helps.

0

You need to:

  1. make an empty layout
  2. add a container for the block in the layout(.xml)
  3. figure out the block name from the existing magento code
  4. place the block into your container (there are noumerous stacks how to do this)

Not a great answer but your question is just too broad.

0

First of all thanks for your answers :).

I thought the question was straight forward but I will expand on it to try to make it clearer.

I have added a custom layout homepage-layout.xml to Magento_Theme (and the corresponding layouts.xml so I can select the new layout in the home page "design->layout").

<mytheme_dir>/Magento_Theme

if I put the following in a new homepage-layout.xml file:

<?xml version="1.0" ?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <update handle="empty"/>
    <referenceContainer name="page.wrapper">
        <container name="header.container" as="header_container" label="Page Header Container"  htmlTag="header" htmlClass="page-header" before="main.content"/>
    </referenceContainer>
</layout>

Unfortunately It includes the "logo", "search entire store" and "shopping card" blocks/items and I only want the top bar with the language picker.

If I add the block directly into the homepage-layout.xml it seems to be ignored.

<?xml version="1.0" ?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <update handle="empty"/>
    <referenceContainer name="page.wrapper">
        <block class="Magento\Store\Block\Switcher" name="store_language" as="store_language" template="switch/languages.phtml"/>
    </referenceContainer>
</layout>

I do not want to override the default.xml because that would change the layout of all the pages in my shop and I just want to change it for the home-page.

So it seems that I need to "copy" the stripped content of the "default.xml" to a new file I have called "home.xml" and referenced that file instead of the "default.xml" file.

<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="default_head_blocks"/>
    <body>
        <block name="require.js" class="Magento\Framework\View\Element\Template" template="Magento_Theme::page/js/require_js.phtml" />
        <referenceContainer name="header.container">
            <container name="header.panel.wrapper" htmlClass="panel wrapper" htmlTag="div" before="-">
                <container name="header.panel" label="Page Header Panel" htmlTag="div" htmlClass="panel header">
                    <block class="Magento\Store\Block\Switcher" name="store_language" as="store_language" template="switch/languages.phtml"/>
                </container>
            </container>
        </referenceContainer>
    </body>
</page>

The problem is that it is not clear to me if this is the right way to do it. If it is I have no clue of how to have the home.xml referenced instead of the default.xml.

Any help greatly appreciated.

  • 1
    Please update the question using the "edit" link if you want to add additional information. Answers are only meant for actual answers (i.e. solutions) – Fabian Schmengler Apr 21 '17 at 19:23
0

This is my current solution:

Create a new theme:

app/design/frontend/VENDOR/THEME/

Create file:

app/design/frontend/VENDOR/THEME/Magento_Theme/page_layout/homepage-layout.xml

Content:

Pay special attation to container name="homepage.container"

<?xml version="1.0" ?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
   <update handle="empty"/>
   <referenceContainer name="page.wrapper">
       <container name="homepage.container" as="header_container" label="Page Header Container"  htmlTag="header" htmlClass="page-header" before="main.content"/>
   </referenceContainer>
</layout>

Create file:

app/design/frontend/VENDOR/THEME/Magento_Theme/layouts.xml Content:

<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">
   <layout id="homepage-layout">
       <label translate="true">Homepage Layout</label>
   </layout>
</page_layouts>

Assign it to a page: • Content->”elements”->pages • Action->Edit • “Design”->Layout

Create a new module:

/magento/app/code/VENDOR/MODULE/

Create file: /magento/app/code/VENDOR/MODULE/view/frontend/layout/cms_index_index.xml

Content:

<?xml version="1.0"?>
<page layout="1columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <body>
       <referenceContainer name="homepage.container">
           <container name="header.panel.wrapper" htmlClass="panel wrapper" htmlTag="div" before="-">
               <container name="header.panel" label="Page Header Panel" htmlTag="div" htmlClass="panel header">
                    <block class="Magento\Store\Block\Switcher" name="store_language" as="store_language" template="switch/languages.phtml"/>
               </container>
           </container>
       </referenceContainer>
       <referenceContainer name="content">
            <block class="**VENDOR**\**MODULE**\Block\Tables" template="**VENDOR**_**MODULE**::homepage.phtml"/>
       </referenceContainer>
   </body>
</page>

Avoid separate header block:

<?xml version="1.0"?>
<page layout="1columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <body>
       <referenceContainer name="homepage.container">
               <container name="header.panel" label="Page Header Panel" htmlTag="div" htmlClass="panel header">
                    <block class="Magento\Store\Block\Switcher" name="store_language" as="store_language" template="switch/languages.phtml"/>
               </container>
       </referenceContainer>
       <referenceContainer name="content">
            <block class="\**VENDOR**/**MODULE**\Block\Tables" template="**VENDOR**_**MODULE**::homepage.phtml"/>
       </referenceContainer>
   </body>
</page>

Enable created module, Assign created theme, Refresh cache etc.

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.