We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8216
    • 15 Posts
    Howdy all.

    How do I have an optional block of HTML in a template? I want to have an newsletter sign-up but only on some pages and not in the content area - I don’t really want to have another template. I’m hoping to have a checkbox (a TV perhaps?) for a template. When it is checked, it will show the form (a Chunk?). It’s for a client so the simplest way is the best way.

    Thanks in advance.
      modx ist rad
      • 8960
      • 150 Posts
      I’ll take a stab at this.


      • First you’ll want to create a TV (Template Variable), let’s call it NewsletterSignup (you can also use ’Display Newletter Signup’ as the caption and ’Description for NewsletterSignup.’ as the description).
      • Choose Check Box as the Input Type and enter something like Display Signup=={{NLsignup}} for the Input Option Values. The Display Signup is the text label and the {{NLsignup}} is the signup Chunk you’ll create in a minute.
      • Check off which template this will apply to.
      • Save this TV.
      • Add your TV call to that template whereever you want your signup code to be displayed: [*NewsletterSignup*]
      • Next, create a new Chunk for your signup code. Call your chunk NLsignup because that’s what we called it in the TV.
      • Paste in your signup code.
      • Save the chunk and you are done.

      Now on each document, you should be able to see the TV checkbox and select whether or not you want that TV, the Newsletter Signup, on each page.

      Damn I love MODx!
        • 34017
        • 898 Posts
        er,

        How would you do this with "inheritance"? So if you check the box in the parent document, it will show in all of the child documents, unless you uncheck it?

        Chuck
          Chuck the Trukk
          ProWebscape.com :: Nashville-WebDesign.com
          - - - - - - - -
          What are TV's? Here's some info below.
          http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
          http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
          • 8960
          • 150 Posts
          I actually know nothing about @INHERIT or any of the @BINDINGS, yet. Funny enough, I just read a post about what you’re asking about earlier today. OpenGeek mentioned something about a misconception about @INHERIT in this thread, so pay attention to that.

          Look at that... the possible answer just came in from Ryan at another post I’m involved in.
            • 33372
            • 1,611 Posts
            Quote from: er16004 at Mar 22, 2007, 08:39 PM

            I’ll take a stab at this.


            • First you’ll want to create a TV (Template Variable), let’s call it NewsletterSignup (you can also use ’Display Newletter Signup’ as the caption and ’Description for NewsletterSignup.’ as the description).
            • Choose Check Box as the Input Type and enter something like Display Signup=={{NLsignup}} for the Input Option Values. The Display Signup is the text label and the {{NLsignup}} is the signup Chunk you’ll create in a minute.
            • Check off which template this will apply to.
            • Save this TV.
            • Add your TV call to that template whereever you want your signup code to be displayed: [*NewsletterSignup*]
            • Next, create a new Chunk for your signup code. Call your chunk NLsignup because that’s what we called it in the TV.
            • Past in your signup code.
            • Save the chunk and you are done.

            Now on each document, you should be able to see the TV checkbox and select whether or not you want that TV, the Newsletter Signup, on each page.

            Damn I love MODx!

            An excellent answer - you explained it perfectly!
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn't very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
              • 8216
              • 15 Posts
              Awesome - worked perfectly.

              MODx rocks my socks. It’s fantastic for stuff like this. If you can think it, MODx can do it.
              It is a bit of tough nut to crack though. I’m still trying to get my head around how all these bits and pieces click in together.

              Thanks again.
                modx ist rad
              • Don’t worry, as soon as you get it all under control you’ll find everything has been updated and improved to the point where you get to start all over again! grin
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 8216
                  • 15 Posts
                  I get it a bit more now - the TV will be replaced with the Chunk I specify. Simple. I like MODx even more smiley
                  I’ve even experimented (for extra credit) and added a pop up menu with a selection of chunks. Very cool.

                  And this gave me a thought - how would I go about having a pop up menu, such as the one above, automatically generated? So, for instance, I could have a container of documents - which the editors could add to ad hoc - that provide the options.

                  Would this be done via a DB binding? Query the MODx DB? Is that getting too complicated? I would welcome any thoughts.
                    modx ist rad
                    • 8216
                    • 15 Posts
                    For anyone that’s interested: there’s a great tutorial right here:
                    http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks

                    This will kinda do what I suggested above with a bit of modification.
                    Over and out.
                      modx ist rad
                      • 32319
                      • 129 Posts
                      I think a good way to do this would be to use an @chunk binding.


                      • Create a new TV
                      • Choose a variable name and caption for your TV
                      • Input Type: [tt]Check Box[/tt]
                      • Input Option Values: [tt]Chunk One == @CHUNK chunk1 || Chunk Two == @CHUNK chunk2[/tt] where [tt]chunk1[/tt] and [tt]chunk2[/tt] are the names of your chunks
                      • Assign the TV to the templates that require it.
                      • Create your chunks if you have not already.
                      • Put the TV call in your template (For example [tt][*chunktv*][/tt])

                      You should now have two nifty check box options on the edit pages using the above template.

                      I am not sure the technical advantages to this method over just calling the chunk name (i.e. [tt]{{chunk1}}[/tt]) directly but it seems like it would cut out at least one cycle of reference. Any comments?

                      Quote from: ProWebscape at Mar 22, 2007, 10:27 PM

                      How would you do this with "inheritance"? So if you check the box in the parent document, it will show in all of the child documents, unless you uncheck it?
                      For inheritance, use the @INHERIT binding:
                      http://www.modxcms.com/inherit-binding.html

                      To add Inheritance you can set a Default Value of: [tt]@INHERIT @CHUNK chunk3[/tt]
                      This will set the default value of the TV to the contents of chunk3 if no check box has been selected on the document or its parents documents.

                      The nice thing about this setup is that chunk3 shows up when no check boxes are selected. If you want to return to the default chunk, just clear the check boxes.

                      Of course, you can mix and match these bindings for a huge amount of options. For example, one check box could bring in a chunk, another text from a file and the third, database data.
                        "Regret for the things we did can be tempered by time; it is regret for the things we did not do that is inconsolable."
                        -- Sydney Harris