We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37031
    • 93 Posts
    Hi everyone! I believe I've exhausted every resource within my reach and am looking for any sort of guidance for a seemingly simple issue.

    I'm calling my snippet uncached on a template. The snippet gets TV values from the current resource and sets those values as placeholders. A web user viewing the page can submit a form which updates the TV values (verified in database) and reloads the page. When the page reloads, TV values do not update.

    My snippet call on the template:
    [[!getAssignmentTV? &pid=`[[*id]]`]]


    My placeholders on the template:
    [[!+a.progress]]
    [[!+a.status]]


    My snippet:
    if (!empty($pid) && is_numeric($pid)) {
    
    	$assignment = $modx->getObject('modResource', $pid);
    	$modx->setPlaceholder('a.progress', $assignment->getTVValue('assign-progress'));
    	$modx->setPlaceholder('a.status', $assignment->getTVValue('assign-status'));
    
    }
    return;


    For the life of me I can't figure out why my snippet and the placeholders are being cached despite being called with the (!) token. Does anyone have any ideas?

    Thank you for your help!
    Jeff

    MODX Revo 2.2.5-pl
    PHP 5.3.18
    MySQL 5.1.65-cll

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      had the same issues.

      $assignment->getTVValue('assign-progress')


      and also

      $tv->renderOutput($pid)


      and

      $tv->getValue($pid)


      seems to cache the value somewhere in the process.

      you can try something like this:

      <?php
      
      $tvnames = 'assign-progress,assign-status';
      $tvnames = explode(',', $tvnames);
      
      if ($tvs = $modx->getCollection('modTemplateVar', array('name:IN' => $tvnames))) {
          foreach ($tvs as $tv) {
              $tvresource = $modx->getObject('modTemplateVarResource', array('tmplvarid' => $tv->get('id'), 'contentid' => $pid));
              
              $ph = str_replace('assign-','a.',$tv->get('name'));
             
              $modx->setPlaceholder($ph,$tvresource->get('value'));
          }
      }
      
      [ed. note: Bruno17 last edited this post 13 years, 9 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37031
        • 93 Posts
        Thanks for the response Bruno.

        I used your suggested code above in my snippet and received the following error:

        Fatal error: Call to a member function get() on a non-object in /path/to/modx/core/cache/includes/elements/modsnippet/57.include.cache.php on line 20

        which refers to the line

        $tvresource = $modx->getObject('modTemplateVarResource', array('tmplvarid' => $tv->get('id'), 'contentid' => $pid));


        Syntax seems correct to me, albeit I'm not well versed in the MODX API. Thoughts?
          • 37031
          • 93 Posts
          I'm using the (!) token to call the snippet uncached but it's still being cached. Is this a bug that I should be reporting?

          I've found similar issues reported where the placeholders disappear after refreshing but those seem to be solved (http://tracker.modx.com/issues/4476). Should I simply be setting the entire resource as uncacheable?
            • 37031
            • 93 Posts
            Bruno, I just wanted to say thank you for suggesting the snippet code above. The exception I was getting was my own typo mistake. Using your code above seems to be a good workaround. For the life of me though I still can't understand why the (!) token isn't working. Does anyone else have any experience with this?
              • 4172
              • 5,888 Posts
              As said above:


              had the same issues.

              $assignment->getTVValue('assign-progress')


              and also

              $tv->renderOutput($pid)


              and

              $tv->getValue($pid)


              seems to cache the value somewhere in the process.

              this api-methods seems to use some caching somewhere.
              So the result of $assignment->getTVValue('assign-progress') is cached, not the result of your snippet at all.

              couldn't find a cache-flag or something for this methods, so I used xpdo directly to get the changed value.
              Another option could be to refresh the cache after changing values.

              It doesn't make a difference for the api-method, if you call your snippet cached or uncached.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 37031
                • 93 Posts
                Ahh, thanks for clarifying Bruno. I'll watch out for similar issues with the other methods you mentioned as well. And thanks again for the guidance!