We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50272
    • 89 Posts
    geordiechris Reply #1, 10 years ago
    Hi Folks

    All I'm trying to create is a TV consisting of a couple of check boxes;
    one marked 'on' and one 'off', which when selected,
    will show/hide a small chunk of html.

    I could only find this thread from some eight years ago...
    https://forums.modx.com/thread/9799/toggling-a-chunk-on-and-off-tv-problems
    But I was wondering if there is any more recent development.

    The 'ToggleTVSet' Extra seems a little overkill just to add/remove what is basically a <p> tag.
    That said, maybe creating two TV's that can be selected accordingly may be the way forward.

    Any suggestions as to how perhaps I should begin thinking around this
    would be much appreciated.

    Many Thanks
    Chris

    I'm using:
    MODX 2.5.1
    MAMP (latest (3.0.7.3))
    PHP (5.5.18)
    MySQL (5.5.38)
    Chrome: Std and Canary (latest versions)
    Mac OX (Mountain Lion-10.8.5).

    This question has been answered by geordiechris. See the first response.

    [ed. note: geordiechris last edited this post 10 years ago.]
      • 17301
      • 932 Posts
      I would guess this would work..

      Create a template variable and then if checked display the chunk.

      [[*templateVariable:notempty=`[[$chunk]]`]]
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 3749
        • 24,544 Posts
        You could also do it with a short snippet:

        $show = $modx->resource->getTVValue('TvName'); 
        
        if (!empty($show)) {
            return $modx->getChunk('ChunkName');
        } else {
            return "";
        }

          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 50272
          • 89 Posts
          geordiechris Reply #4, 10 years ago
          Thanks Guys

          I'm aware that there are many ways of doing the same thing in modx.
          I'm therefore in the throes of getting to grips with the possibilities of combining TV's, snippets and chunks,
          and what might be the most efficient ways in which to utilise these building blocks.

          I have tried both suggestions and indeed, after a little tweaking, get the results I'm after.
          Basically I'm trying to create an on/off switch that displays/hides an occasional discount callout.
          So in the interest of my learning, how does the following stack up in terms of understanding/efficiency?

          TvName > Input Type : Radio Options  
          Input values : No==[[$chunk]]||Yes==[[$chunk_with_discount]]  
          default: No==[[$chunk]]
          
          Template call: [[!*TvName]]


          Any feedback would be great

          Many Thanks

            • 3749
            • 24,544 Posts
            I think the snippet would be slightly faster, but the difference is probably small and the convenience of the radio options is nice to have.

            The snippet could be made to work with the radio options, but I'm not sure it's worth the trouble.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
            • discuss.answer
              • 50272
              • 89 Posts
              geordiechris Reply #6, 10 years ago
              Good to get a thumbs up Bob.
              Thanks for the feedback