We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24981
    • 109 Posts
    Hi,

    I’m looking for a simple way to repeat Template Variables. In previous design, I have created a number of TVs as "advertisement blocks" set in a right column eg AdvertBlock1, AdvertBlock2. Then, if admin doesn’t complete all blocks, you are left with empty divs.

    The problem with doing it this way:
    * It clutters the interface for backend of each page; you have to load the WYSIWYG icons for all blocks even if you aren’t using them.
    * If you apply some styles to divs eg. borders, then the the empty div will appear on the page.

    What would be good would be the ability to set a repeat for a Template Variable in the page. By default the TV would appear once, but in each page you would be able to set a repeat value next to each TV title. When you change the value to 2, and Save the page reloads with 2 TVs.

    Any ideas on how to achieve this, or other solutions [other than amalgamating the TVs into a single TV and relying on the editor to format the content using the WYSIWYG editor]

    Thanks

    Richard
      • 33337
      • 3,975 Posts
      I am not coder myself, but Mark created a nice snippet to implement simple checkbox condition: http://modxcms.com/forums/index.php/topic,3083.msg21745.html#msg21745

      This might help you getting there.

      regards,

      zi
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 29635
        • 361 Posts
        Hey Richard,
        I know this isn’t an answer to your question, but it’s an alternate solution you might not have considered:
        You could try using one of the snippets on this post:
        http://modxcms.com/forums/index.php/topic,2940.msg31972.html#msg31972

        Checks to see if the TV is empty; if it is, it returns nothing (no empty div); if TV is not empty, it’ll output the TV plus the widget or any extra code you have in the snippet output. It’s designed to use with a widget (which will still display even if the TV is empty (bug)), but you could really easily hack the snippet to include the DIVs you want right in the snippet output. That’s what I’ve done when I have TVs that may or may not appear, but empty divs (or img tags) look ugly.

        Super fast example if you’re not using a widget:
        return '<div class="testing">'.$output.'</div>';

        Will not return an empty div if the TV is empty, which is what you’re looking to do, right?

        Hope that helps.
        -Brett
          Need MODx Ecommerce? Try FoxyCart!