We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12071
    • 3 Posts
    I’m new to MODx so I’m not sure if this can be done and if so, how. I am trying to create a template variable that would make it easier for users to update values inside <script> tags in the content editor.

    Basically, the page looks something like this:
    1.<script type="text/javascript"><!--scriptname(value1, value2, value3);// --></script>
    2.<script type="text/javascript"><!--scriptname(value1, value2, value3);// --></script>
    3.<script type="text/javascript"><!--scriptname(value1, value2, value3);// --></script>
    4.<script type="text/javascript"><!--scriptname(value1, value2, value3);// --></script>

    I need a simple way for people to go in and edit each ’value3’ without having to touch the raw code and I was thinking a tv would work. What would be the best way to go about this?

    Thanks.
      • 21257 MODX Staff
      • 730 Posts
      That would work. If you use a TV, then it will have to have it’s value set (i.e. edited) on each page that contains the script. Depending on how your site is set up, if you had a container where you wanted each of the child documents to inherit the value of the TV from the container, you could set the TV’s default value to the special value @INHERIT.
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 22770
        • 285 Posts
        If I understand you correctly, a TV would work fine. For example, create a TV called value3.

        Then you code would be:

        <script type="text/javascript"><!--scriptname(value1, value2, [*value3*]);// --></script>
        <script type="text/javascript"><!--scriptname(value1, value2, [*value3*]);// --></script>
        <script type="text/javascript"><!--scriptname(value1, value2, [*value3*]);// --></script>
        <script type="text/javascript"><!--scriptname(value1, value2, [*value3*]);// --></script>

        Not that I’ve tested it, but it makes sense to me! grin
          • 12071
          • 3 Posts
          netProphET - There are no children for the page - perhaps I don’t completely understand what you’re getting at?

          Patrick - That pretty much sounds like what I want to do but I’m not entirely sure how to get it done. Each of the ’value3’s would need a separate entry field and I haven’t figured out how to do that either.
            • 21257 MODX Staff
            • 730 Posts
            @hertz - if this is just for one page then it’s much easier - forget what I’m saying about multiple pages smiley
              Mike Schell
              Lead Developer, MODX Cloud
              Email: [email protected]
              GitHub: https://github.com/netProphET/
              Twitter: @mkschell
              • 22770
              • 285 Posts
              Quote from: hertz at Feb 09, 2009, 02:52 PM


              Patrick - That pretty much sounds like what I want to do but I’m not entirely sure how to get it done. Each of the ’value3’s would need a separate entry field and I haven’t figured out how to do that either.

              Okay. What you need to do is create a separate TV for each of the 4 javascripts. Call them whatever you like (valuea, valueb, etc). Make sure you assign the TVs to the relevant template(s). Use [*valuea*] etc as a placeholder where you want the value to appear in the code. Then, when you create a new page or edit an existing one using that template, the fields will be available.
                • 12071
                • 3 Posts
                Brilliant! Thank you, that works perfectly.

                So I guess I do need to make multiple template variables. I was hoping one would be enough.