i see this post

I want to do the same but with a condition. I want to call an helper function which return a boolean. And in my xml do like :

    <?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="ajax-empty" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceContainer name="root">
            <block class="Magento\Framework\View\Element\Template" name="customer.account.popin" template="MyVendor_Customer::form/popin_disconnected_content.phtml">
                IF USER IS LOGGED IN
                    <block class="Magento\Framework\View\Element\Messages" name="messages"/>
                    <block class="Magento\Customer\Block\Form\Login\Info" name="customer.account.popin.register" template="Magento_Customer::newcustomer.phtml"/>
                    <block class="Magento\Customer\Block\Form\Login" name="customer.account.popin.login" template="Magento_Customer::form/login.phtml">
                        <block class="Magento\Persistent\Block\Form\Remember" name="remember_me" template="Magento_Persistent::remember_me.phtml" ifconfig="persistent/options/enabled" as="form_additional_info"/>
                IF USER IS NOT LOGGED IN
                    <block class="Magento\Customer\Block\Form\Login\Info" name="customer.account.popin.register" template="Magento_Customer::newcustomer.phtml"/>

How can I do this ?

EDIT : this is like I want to do but it's with observers and I'm too weak with magento 2 config to change it for helpers, can you help me please ?


Please, refer to this link, http://inchoo.net/magento/custom-layout-update-handles/. It could help you. Use the following to call a function from Helper inside layout.

 <action method="setStorVar">
<var helper="module/getStoreVar" />

| improve this answer | |

Customer logged out and log in handles are now removed so your simplest approach is to create your custom blocks extending the ones you want to add and check if customer is logged in in _toHtml() method in each block. If not render the block and if he is return empty string in order not to render them.

| improve this answer | |
  • I can't do this because my structure is a lot complicated I will update my post to explain my problem – Kpone Feb 27 '17 at 11:00

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.