We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26931
    • 2,314 Posts
    Hi there,

    i try to return the value of a snippet which is placed inside a ditto template chunk. but no matter how i set and change the caching i get no output. if i call the snippet on the ressource page itself it works.
    [!Ditto? &parents=`59` &depth=`1` &display=`all` &sortBy=`menuindex` &sortDir=`ASC` &tpl=`calendarTpl` &hiddenFields=`enddatetv` !]
    on a non cached ressource, with the template "calendarTpl"
    <div class="cal">
        <h3 class="calheader">[+pagetitle+] / [+startdate+] [[enddate]]</h3>
        <div class="calcontent">[+content+]</div>
    </div>
    and the snippet "enddate":
    <?php
    $output="";
    $id=$modx->documentIdentifier;
    $document_tvs = $modx->getTemplateVarOutput(true, $id);
    $enddate=$document_tvs['enddatetv'];
    
    if (!empty($enddate['value'])) {
             $output = $enddate;
             return $output;
    }
    ?>

    calling the template via @File property in order to avoid caching problems http://modxrules.com/articles/take-advantage-of-dittos-file-property didn’t work as well. a simple snippet call e.g.
    <?php return "test"; ?>
    does work, so it’s probably snippet code related. i’m doing this because i try to avoid PHX btw.

    any ideas what i’m doing wrong?

    thanks, j
      • 10449
      • 956 Posts
      just a guess... but sometimes using echo() instead of return() works, especially when using nested chunks/snippets
        • 4172
        • 5,888 Posts
        I think you need the id of each ditto-iteration:

        <?php
        $output="";
        //$id=$modx->documentIdentifier;
        $document_tvs = $modx->getTemplateVarOutput(true, $id);
        $enddate=$document_tvs['enddatetv'];
        
        if (!empty($enddate['value'])) {
                 $output = $enddate;
                 return $output;
        }
        ?>


        and call it with:
        [[yoursnippet? &id=`[+id+]`]]
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 26931
          • 2,314 Posts
          thanks to both of you

          Brunos suggestion worked smiley