We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36565
    • 73 Posts
    Hi all. I am having a getResources call in a 'master' document that pulls in the resources that are contained in that document, templated by a chunk TE.tpl.

    Inside TE.tpl, I make a TV call to a checkbox TV "HeadingExists", like so:
    [[+tv.HeadingExists]]


    HeadingExists's purpose is to call a chunk $Heading when checked. And really, that chunk is called and included in just those resources pulled by getResources that have HeadingExists checked. Fine!

    But.

    Inside $Heading, there are two more TV calls, like so:
    <h2>[[+tv.Heading]]<em class="heading_description">[[+tv.Description]]</em></h2>

    The purpose of these TVs is, of course, to deliver the heading and the description of the resource I aim to pull into the 'master' resource, and that's what they do: Looking at the arrays getResources throws at me when calling it with no template, each pulled resource shows its TV values just as I set them to be. Fine still.

    The problem is that in the 'master' resource, the pulled-in resources are rendered all with the Heading and Description of the first pulled-in resource.

    Judging from some posts about getResources' purpose not being to work with dynamic portions of resources, which I am not quite sure what to make of, this may or may not be expected behaviour. If it is - is there any other way to do what I'm trying to do? Symlinks? But you cannot add some of these up into another resource, can you?
      PHP illiterate MODx enthusiast
      • 33968
      • 863 Posts
      I didn't really understand what's going on here - can you post your getResources call?

      Also, is the purpose of HeadingExists simply to indicate whether the 'Heading' field is empty or not? If so, you can do that with an output modifier instead:
      [[+tv.Heading:notempty=`[[+tv.Heading]]`]]
      
      [ed. note: okyanet last edited this post 15 years, 1 month ago.]
        • 36565
        • 73 Posts
        So this is my getResources call:
        [[getResources? &showHidden=`1` &showUnpublished=`1` &includeContent=`1` &includeTVs=`1` &processTVs=`1` &parents=`31` &sortby=`menuindex` &sortdir=`ASC` &tpl=`TE.tpl` &depth=`1`]]


        This is the content of TE.tpl:
        <div>
           [[+tv.TE-HeadingExists]]
           [[+content]]
        </div>


        This is the Input Option Value of the checkbox TV TE-HeadingExists:
        Yes==[[$TE-Heading]]


        And this is again the content of $TE-Heading:
        <h2>[[+tv.Heading]]<em class="heading_description">[[+tv.Description]]</em></h2>


        Now yes, that's the purpose of HeadingExists: to save me the <h2><em ...></em></h2> tags when they are empty. Thanks for prodding me at output modifiers; I'll see if I can get that to work. Still, I'm interested in whether that behaviour of getResources' is expected or not.

        By the way, what does
        [[tv.Heading]]
        (syntax without a +) mean? [ed. note: neo2.0 last edited this post 15 years, 1 month ago.]
          PHP illiterate MODx enthusiast
          • 33968
          • 863 Posts
          By the way, what does
          [[tv.Heading]]

          (syntax without a +) mean?
          That would mean a typo smiley

          For your case it would be:
          [[+tv.Heading:notempty=`<h2><em>[[+tv.Heading]]</em></h2>`]]
          

          So the html tags will be skipped if the heading is empty. You don't need the other tv.

          I think the reason you are getting only the first heading output is because the
          [[+tv.TE-HeadingExists]]
          placeholder is being cached the first time. You could try it uncached like this:
          [[!+tv.TE-HeadingExists]]


          But it would be much simpler using the output modifier as above.
          [ed. note: okyanet last edited this post 15 years, 1 month ago.]
            • 36565
            • 73 Posts
            Well! Lucas, you made my day. Thanks a lot, your suggestion has helped me very much.

            And: I didn't know about the possibility of calling the TV uncached. In fact I didn't even know I was calling it cached. I'm positive it would work if I added the ! in the tpl-chunk - but now I don't need to do that anymore!

            Again, thanks a ton!

            See you,
            René [ed. note: neo2.0 last edited this post 15 years, 1 month ago.]
              PHP illiterate MODx enthusiast