0

i have to render a page depending upon the logging in customer. so I need to create two home pages basically. If i create a new cms page with admin panel then where it will appear in files because i got to put css,html etc and and insert products links in that page as well?

  • you want to display different home page for logged in and logged out customer? – Naresh Rupareliya Dec 15 '19 at 3:44
  • It is something like this....If X type of customers signs in then render 1st home page else (Y type of customers signs in) render 2nd home page..... – Ankur Anand Dec 15 '19 at 5:59
  • okay got it. i will upload answer in few minutes – Naresh Rupareliya Dec 15 '19 at 6:55
  • Okay....Thanks. – Ankur Anand Dec 15 '19 at 6:57
  • Answer posted. check and let me know it's working for you or not – Naresh Rupareliya Dec 15 '19 at 7:30
1

Download this module Change-Homepage-Based-On-Condition and put in app/code directory and install this module:

Change cms identifier as per your cms page indetifier in below file

NR/Cms/Controller/Index/Index.php

Eaxmple :

In this example i have set deafult Home Page - A for Guest Customer

enter image description here

After Logged In display Home Page - B for Customer.

enter image description here

Hope this will help you!

How to Make XML file for Different Homepage

You need to create two xml file for 2 cms home pages

  1. create homepage-a.xml file under

app/design/frontend/Vendor/Theme/Magento_Theme/page_layout/homepage-a.xml

and use content below :

<?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="1column"/>
    <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="content-a" template="Magento_Theme::html/homepage/content-a.phtml"/>
    </referenceContainer>
</layout>
  1. create homepage-b.xml file under

app/design/frontend/Vendor/Theme/Magento_Theme/page_layout/homepage-b.xml

and use content below :

<?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="1column"/>
    <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="content-b" template="Magento_Theme::html/homepage/content-b.phtml"/>
    </referenceContainer>
</layout>

Override layouts.xml file under

app/design/frontend/Vendor/Theme/Magento_Theme/layouts.xml

and use content below :

<?xml version="1.0" encoding="UTF-8"?>
<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">
    <layout id="1column">
        <label translate="true">1 column</label>
    </layout>
    <layout id="2columns-left">
        <label translate="true">2 columns with left bar</label>
    </layout>
    <layout id="2columns-right">
        <label translate="true">2 columns with right bar</label>
    </layout>
    <layout id="3columns">
        <label translate="true">3 columns</label>
    </layout>
     <layout id="homepage-a">
        <label translate="true">Home Page - A</label>
    </layout>
    <layout id="homepage-b">
        <label translate="true">Home Page - B</label>
    </layout>
</page_layouts>

You need to also create two phtml file for 2 homepage

  1. Create content-a.phtml file for homepage-a content under

app/design/frontend/Vendor/Theme/Magento_Theme/templates/html/homepage/content-a.phtml

and use content below :

<?php echo "Homepage - A"; ?> //put code in this file for Homepage A as per your requirement
  1. Create content-b.phtml file for homepage-b content under

app/design/frontend/Vendor/Theme/Magento_Theme/templates/html/homepage/content-b.phtml

and use content below :

<?php echo "Homepage - B"; ?> //put code in this file for Homepage B as per your requirement

Note : Flush cache

Now time to assign created xml file to our CMS page

  1. Go to Content >> Elements >> Pages >> Edit Homepage A >> Open Design Tab and set Home Page - A to layout and Save Page
  2. Go to Content >> Elements >> Pages >> Edit Homepage B >> Open Design Tab and set Home Page - B to layout and Save Page

Note : Flush cache again and check

Hope this will help you!

|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.