We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37582
    • 65 Posts
    I always thought it is possible to modify resource tags at runtime:

    
    $resouce = $modx->getObject('modResource', array('id' => 2));
    $resource->set('longtitle', 'foo');
    
    


    Even if I include this in a snippet and put it at the beginning of my template it will not affect [*longtitle].

    However, If I do this it returns 'foo':

    return $modx->get('longtitle');
    


    I see that I can manipulate my modResource object, but somehow this has not influence on the page rendering. Is there a way to change this? XPDO?

      • 9207 ☆ A M B ☆
      • 2,475 Posts
      It might be a question of scope... your "$resource" variable isn't global, so changing its attributes won't stick when the template is parsed. I know during some plugin events, for example, you can use
      $modx->resource
      as an alias for the current resource, and since it's attached to the MODX super-variable, that *would* stick around. I don't know if you have access to that variable inside a Snippet however, but it might be worth a try.
        • 3749
        • 24,544 Posts
        You're creating a new object with the data from the resource object in the database. That's not the object being parsed for the page.

        It might (or might not) work to use this:

        $modx->resource->set('longtitle', something); 



        If it makes sense to do what you're doing in a plugin. You can create one attached to OnParseDocument, and just use str_replace to replace the tags before they're parsed. That would be the most efficient.

        If that doesn't work and you want a dynamic longtitle, I'd just replace the longtitle field tag with a snippet tag and have the snippet return whatever you want to go there.

        Another option would be to use a built-in or custom output modifier to use in the longtitle tag.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting