We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6038
    • 228 Posts
    Excited by reading about the idea of how you can now add placeholders to chunks, i thought this would be a good way to add my global js files and any extra js through a tv, so it can be customised for each page.

    So i have a main chunk called ’js_files’ which is called in the template, and a tv called extraJS
    i call the chunk in my template like so:
    [[$js_files? &extras=`[[*extraJS]]`]


    Into the extraJS tv i put a chunk name: eg [[$specialJS]]
    but the extra files dont appear!

    Im sure this must have something to do with source order parsing, but I’m not sure why - as I thought that revo could do infinite recursion with the tags. If i put a text value into the tv, it passes through ok - but not a chunk name. Is this a restriction? Or am i doing something I shouldn’t be?
      • 14883 ☆ A M B ☆
      • 450 Posts
      I think what you want to do is this:

      • put just the name of the chunk in the tv value: ’specialJS’, not ’[[$specialJS]]’
      • [li]Call your chunk like this:
      [[$js_files? &extras=`[[*extraJS]]`]]
        [/li]


      That will get parsed down to
      [[$js_files? &extras=`specialJS`]]


      Then, if your js_files chunk looks something like this:
      <script src="somescript"></script>
      <script src="someotherscript"></script>
      [[$[[+extras]]]]
      


      That will become
      <script src="somescript"></script>
      <script src="someotherscript"></script>
      [[$specialJS]]
      


      That should do the trick.

      However...

      An even easier way is to just put the TV call directly inside the chunk contents - no need to pass it in as an argument that fills a placeholder:
      <script src="somescript"></script>
      <script src="someotherscript"></script>
      [[$[[*extraJS]]]]
      


      You don’t need to pass it as an argument at all. The parser will find the TV call in the chunk. This is one of the cool underrated features of MODx.
        • 6038
        • 228 Posts
        the second method is definitely the preferred - it would allow you to add more than one chunk name, which the first method wouldn’t. And its stupidly simple! Sometimes I have this knack of making things more complicated than they need to be - DOH!

        But on testing, I cant put a chunk reference into the template var and get anything to come out...
        I’ve tested by putting the tv in the first chunk, and setting the tv val in the resource to a chunk reference,
        and i’ve also tested by creating another tv which is wrapped in another set of tag brackets (as per your example) and then just setting the tv val to the chunk name only - but neither works for me - there is no ouput to the document... Hmmm.

        I’ve also created a third tv and added this to the first chunk, but only using text in the chunk... nothing. something seems a bit suss here. mmm.
        Tried using both placeholder and document object formats eg [[+name]] and [[*name]] in the chunk - but neither seem to be working.... what am i doing wrong here?? I have given the tvs permission to be accessed in that template - otherwise, i couldn’t have entered a value.

        I think i might have to dump this install and try again, as one of my resources has been absent from the tree, though i can see it is in the db table. I might have stuffed it because i created some test pages, then installed the sample site package over everything... since then, one of my original documents has gone AWOL though it is in the database.



          • 14883 ☆ A M B ☆
          • 450 Posts
          You’d still have to specify a single chunk name with this method, since it gets subbed into a call for a single chunk. I can’t imagine why you’d need to name more than one chunk for this purpose anyway; you can specify as many javascript files as you’d like inside of that one chunk.

          Do you have your TV Output type set to something other than Default?

          Have you tested just putting a basic TV call in your template (not nested inside another tag or used as an argument)? <p>[[*extraJS]]</p>. If you put just the name of a chunk in as your TV value, you should see it (the name string) come through in your HTML. Then you know your TV is working, and should work for nesting like [[$[[*extraJS]]]]. If you can’t get the TV value to come through plain like that, then something screwy is going on.
            • 6038
            • 228 Posts
            Quote from: jrotering at Jun 17, 2010, 11:10 PM

            I can’t imagine why you’d need to name more than one chunk for this purpose
            Its just an idea to group js files related to different features eg slideshow, accordion feature, tablesorting etc so the groups could be added on a ’by page’ basis.

            Quote from: jrotering at Jun 17, 2010, 11:10 PM

            Do you have your TV Output type set to something other than Default?
            Nope.

            Quote from: jrotering at Jun 17, 2010, 11:10 PM

            Have you tested just putting a basic TV call in your template (not nested inside another tag or used as an argument)?
            Sound idea. Have tried it and nothing comes through, so something very weird is going on - I’m going to reinstall.
            Thanks James - btw, love your blog, keep it up!