10 Replies Latest reply on Nov 20, 2018 1:10 PM by Sanford Whiteman

    Email Booleans - How do you implement them?

    Geoff Krajeski

      Anyone know how a boolean in email works or have an example, as in to toggle images/areas on & off?


      Can you help with how they work? 

      If I'm toggling an element in page shouldn't there be some correlating name/id?


      The documentation is not 100% there on how you would actually do this.



        • Re: Email Booleans - How do you implement them?
          Grégoire Michel

          Hi Geoffrey,


          No much time to paste some code not, but usually, the boolean variable will in fact get the values "none" or "block" or whatever CSS value that makes sense.


          Then in your code, you will have something in your code under the form of


          <img style="display:${myBooleanVariable}">


          BtW, hiding elements using booleans is acceptable in landing pages but not really recommended in emails. Because 1/ some email clients will not correctly interpret the CSS above and 2/ the image has to load even if it does not display, which is not good for deliverability or performance. It's much better to use modules instead, because these really add or remove the code for the email.



          • Re: Email Booleans - How do you implement them?
            Paul Hughes

            I haven't seen this solution on the community page, but I use HTML comment tags to toggle large sections of code on / off with Email 2.0's boolean functionality:


            At the top, I declare:

            <meta class="mktoBoolean" id="showSection" mktoName="Show Section?" default="true" true_value="-->" false_value="" true_value_name="YES" false_value_name="NO" mktoModuleScope="true">


            Then, I place comments around the section I want to toggle on/off:

            <!-- Section Conditional Trigger ${showSection}

                 [As much code as you want]

            <!-- End Conditional -->


            When the "Show Section" boolean is set to "true", the top conditional is closed, and the code is shown as normal. When the boolean is false, the top comment is left open. This causes the client to comment everything in the code out until the bottom comment, whose closing bracket prevents the entire rest of the document from being commented out. Comments are universally supported, so this doesn't run into any client issues (unlike trying to use display). And, since hidden images are commented out, the user's email client won't try to load it.


            I have found this to work reasonably well, and other variables can be placed within the commented section.

            2 of 2 people found this helpful