Remove block from layout depends on condition

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















I want to remove block product.info.addtocart from layout depends on some conditions










share|improve this question



















  • 1





    We need more information.

    – St3phan
    Feb 12 at 13:16















1















I want to remove block product.info.addtocart from layout depends on some conditions










share|improve this question



















  • 1





    We need more information.

    – St3phan
    Feb 12 at 13:16













1












1








1








I want to remove block product.info.addtocart from layout depends on some conditions










share|improve this question
















I want to remove block product.info.addtocart from layout depends on some conditions







magento2 layout addtocart






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 12 at 12:54









Shoaib Munir

1,6881626




1,6881626










asked Feb 12 at 12:52









Serhii HavrylchukSerhii Havrylchuk

14011




14011







  • 1





    We need more information.

    – St3phan
    Feb 12 at 13:16












  • 1





    We need more information.

    – St3phan
    Feb 12 at 13:16







1




1





We need more information.

– St3phan
Feb 12 at 13:16





We need more information.

– St3phan
Feb 12 at 13:16










2 Answers
2






active

oldest

votes


















1














You can use ifconfig on block



<block class=“…” ifconfig=“section/group/field” name=“product.info.addtocart” />


Or you can use helper:



<block name="product.info.addtocart" class="...">
<action method="setTemplate">
<argument name="template" xsi:type="helper" helper=“VendornameModulenameHelperData::method”>
<param name="name">Vendorname_Modulename::data/template.phtml</param>
</argument>
</action>
</block>


The result in both cases it must to be boolean.



If you want to use in other cases, we need more details.






share|improve this answer























  • With helper worked

    – Serhii Havrylchuk
    Feb 12 at 13:41


















2














You can't remove block based on conditions in layout except system value(ifconfig) but you can do this from controller.



e.g)



if(here your condition)

$layout = $this->getLayout();
$layout->unsetElement('product.info.addtocart'); //block name



I hope it helps you.






share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f261435%2fremove-block-from-layout-depends-on-condition%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You can use ifconfig on block



    <block class=“…” ifconfig=“section/group/field” name=“product.info.addtocart” />


    Or you can use helper:



    <block name="product.info.addtocart" class="...">
    <action method="setTemplate">
    <argument name="template" xsi:type="helper" helper=“VendornameModulenameHelperData::method”>
    <param name="name">Vendorname_Modulename::data/template.phtml</param>
    </argument>
    </action>
    </block>


    The result in both cases it must to be boolean.



    If you want to use in other cases, we need more details.






    share|improve this answer























    • With helper worked

      – Serhii Havrylchuk
      Feb 12 at 13:41















    1














    You can use ifconfig on block



    <block class=“…” ifconfig=“section/group/field” name=“product.info.addtocart” />


    Or you can use helper:



    <block name="product.info.addtocart" class="...">
    <action method="setTemplate">
    <argument name="template" xsi:type="helper" helper=“VendornameModulenameHelperData::method”>
    <param name="name">Vendorname_Modulename::data/template.phtml</param>
    </argument>
    </action>
    </block>


    The result in both cases it must to be boolean.



    If you want to use in other cases, we need more details.






    share|improve this answer























    • With helper worked

      – Serhii Havrylchuk
      Feb 12 at 13:41













    1












    1








    1







    You can use ifconfig on block



    <block class=“…” ifconfig=“section/group/field” name=“product.info.addtocart” />


    Or you can use helper:



    <block name="product.info.addtocart" class="...">
    <action method="setTemplate">
    <argument name="template" xsi:type="helper" helper=“VendornameModulenameHelperData::method”>
    <param name="name">Vendorname_Modulename::data/template.phtml</param>
    </argument>
    </action>
    </block>


    The result in both cases it must to be boolean.



    If you want to use in other cases, we need more details.






    share|improve this answer













    You can use ifconfig on block



    <block class=“…” ifconfig=“section/group/field” name=“product.info.addtocart” />


    Or you can use helper:



    <block name="product.info.addtocart" class="...">
    <action method="setTemplate">
    <argument name="template" xsi:type="helper" helper=“VendornameModulenameHelperData::method”>
    <param name="name">Vendorname_Modulename::data/template.phtml</param>
    </argument>
    </action>
    </block>


    The result in both cases it must to be boolean.



    If you want to use in other cases, we need more details.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 12 at 13:24









    St3phanSt3phan

    1,9611136




    1,9611136












    • With helper worked

      – Serhii Havrylchuk
      Feb 12 at 13:41

















    • With helper worked

      – Serhii Havrylchuk
      Feb 12 at 13:41
















    With helper worked

    – Serhii Havrylchuk
    Feb 12 at 13:41





    With helper worked

    – Serhii Havrylchuk
    Feb 12 at 13:41













    2














    You can't remove block based on conditions in layout except system value(ifconfig) but you can do this from controller.



    e.g)



    if(here your condition)

    $layout = $this->getLayout();
    $layout->unsetElement('product.info.addtocart'); //block name



    I hope it helps you.






    share|improve this answer



























      2














      You can't remove block based on conditions in layout except system value(ifconfig) but you can do this from controller.



      e.g)



      if(here your condition)

      $layout = $this->getLayout();
      $layout->unsetElement('product.info.addtocart'); //block name



      I hope it helps you.






      share|improve this answer

























        2












        2








        2







        You can't remove block based on conditions in layout except system value(ifconfig) but you can do this from controller.



        e.g)



        if(here your condition)

        $layout = $this->getLayout();
        $layout->unsetElement('product.info.addtocart'); //block name



        I hope it helps you.






        share|improve this answer













        You can't remove block based on conditions in layout except system value(ifconfig) but you can do this from controller.



        e.g)



        if(here your condition)

        $layout = $this->getLayout();
        $layout->unsetElement('product.info.addtocart'); //block name



        I hope it helps you.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 12 at 13:23









        Bilal UseanBilal Usean

        4,98923689




        4,98923689



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f261435%2fremove-block-from-layout-depends-on-condition%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay