We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17656
    • 4 Posts
    I’m really starting to tear my hair out with this now. Hopefully someone can point out what I’m doing wrong.

    I have a site that has an advertising space on each page. We want the site owner to be able to specify which advert to display on each page. So firstly I have created a basic template for the creation of adverts. This is just a template with an image selector template variable called adspaceImageTV (as the adverts are only ever pre-made images), and a dropdown yes/no tv called adActiveTV, and a URLTV which contains a url for the advert.

    The site owner can then create as many adverts as they like in preparation for selecting which one should be displayed on a particular part of their site.

    So I have created a template variable ’adspacSelectorTV’ associated to each main page template, this is a dropdown list which is created from a search of all the active advert resources and is formatted in to the dropdown TV as follows:

    [+pagetitle+]==[+id+]||

    by doing a loop through all the adverts and formating their data in a list like that it creates a nice drop down list

    Now I can confirm that when a particular advert is selected, that the correct id for the adverts resource is stored in adspaceSelectorTV

    This is all working fine.

    So now for the fancy bit and where my problem starts:

    I want to use the id of the advert stored in the main pages resource via the adspaceSelectorTV to retrieve the values of the advert’s TV’s (URLTV, adspaceImageTV) using $modx->getTemplateVarOutput($tvName, $adID). simple enough yes? no!

    I have a snippet for retrieving the details as follows:

    <?php
    $value = $modx->getTemplateVarOutput($tvName, $adID);
    echo $value[$tvName];
    ?>

    I have a chunk on the main pages of the site for displaying the advert as follows:

    <div class="banner">
    <a href="[[getTV? &adID=`[*adspaceSelectorTV*]` &tvName=`URLTV`]]"><img alt="images/banner02.png" src="[[getTV? &adID=`[*adspaceSelectorTV*]` &tvName=`adspaceImageTV`]]"/></a>
    </div>

    if i replace [*adspaceSelectorTV*] with the actual numeric ID of my adverts resource, it all works fine. when I use the TV in it’s place it doesn’t work. I’ve confirmed that [*adspaceSelectorTV*] is passing the number 116 (adverts id) to the snippet by adding following to my snippet


    echo $adID

    116 is returned in the browser. So the id is definitely being passed. So I have done some more digging in the modx backend. from what I can see the following line in the getTemplateVarOutput function (manager/includes/document.parser.class.inc.php) fails to set the docid I’ve passed and instead grabs the $this->documentIdentifier when I use the TV as the ID in my chunk, but it works when I manually enter the id number in the chunk???

    $docid= intval($docid) ? intval($docid) : $this->documentIdentifier;

    I’m fairly proficient in php, but I’m certainly not a guru, I thought maybe it was something to do with variable types, but when it’s passed to my snippet either as a number (eg &adID=`116`) or as a tv (eg &adID=`[*adspaceSelectorTV*]`) both ways it’s sent through as a string variable, so I’m at a loss to what the difference is.

    Please can someone shed some light on this, otherwise I think it’s a bug. I’d really like to be able to get this site finished with this functionality.

    Cheers
    Paul


      • 4172
      • 5,888 Posts
      may be it has todo with order of parsing cached snippet-calls and TVs.
      Try uncached snippet-call: [!getTV? &adID=`[*adspaceSelectorTV*]` &tvName=`URLTV`!]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 17656
        • 4 Posts
        Hi Bruno17,

        Thanks for the quick response, I didn’t think you could call snippets in un-cached mode via a chunk. whenever I try calling a snippet from a chunk using [!mysnippet!] it just outputs [!mysnippet!] as text to my browser. That aside that still doesn’t explain why, when the snippet param is echo’d via the snippet code it displays 116 when using either a hardcoded value or the TV in the snippet call. Surely a value is a value is it not?

        this line in my snippet

        echo $adID

        returns the same value for both a hard coded value or the TV in the snippet call. I just don’t get it

        :-(
          • 17656
          • 4 Posts
          sorry just to add, that’s in cached mode it returns the same value
            • 4172
            • 5,888 Posts
            normally you can call snippets in chunks uncached, too.
            But when you parse your chund in another snippet, you have to call it reversed (cached if your outer snippet is called uncached)
            Is this chunk called by another snippet? If so, which snippet is it?

            do you really have [+pagetitle+]||[+id+] as option-values? Or do you have real values here?
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 17656
              • 4 Posts
              You champion! ok i’ve tried the un-cached mode and it works haha

              I’m a bit embarrassed I’ve overlooked even attempting to test this. I have no idea why previously I’ve been unable to call snippets in non-cached mode in chunks. Would it make a difference if the chunk was being called via ditto as the tpl param? I thnk that’s when I’ve had the issue calling in un-cached mode

              Thanks again
                • 4172
                • 5,888 Posts
                glad you got it. smiley
                as said above if you call ditto uncached [!Ditto..........!] you have to call snippets in ditto-chunks cached.
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 5340
                  • 1,624 Posts
                  OR use this technique