We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49580
    • 2 Posts
    Dear MODX'ers,

    I'm new to MODX and have recently installed Revolution 2.3.2-pl. I have created a snippet loading all children of a given parent in this manner:

    <?php 
    $parentEventObject = $modx->getObject('modResource', ['pagetitle' => 'events']);
    $query = $modx->newQuery('modResource');
    $query->where(['published' => true, 'parent' => $parentEventObject->get('id')]);
    $query->sortby('menuindex');
    $events = $modx->getCollection('modResource', $query);
    ?>


    During a loop I retrieve template variable (name: fontpageImage) in this way:

    $event->getTVValue('fontpageImage');


    This all works fine. However for one of my resources I choose to switch to another template (containing NO template variables). Despite changing template and clearing cache I actually get the value of TV frontpageImage (from my previous choice of template). How come it doesn't fail with an error calling $event->getTVValue('fontpageImage');?

    Any help appreciated.

    Thanks!

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      • 22840
      • 1,572 Posts
      You will always get the result of the template variable as it is still in the database, by switching template all you are doing is telling the system to show / hide the tv's.

      If you switch back to the original template and empty the tv's, save and then change back to the new template all should be ok.
        • 49580
        • 2 Posts
        Paulp, thank you for a really fast and accurate response. That certainly explains it. Eventhough the current TV idea is pretty global by nature, I think this behaviour is pretty unfortunate since you actually explicitly grant access per template (I can think of some unwanted side effects). Show/hide in resource would be a more suitable name smiley

        Thanks again Paulp!
        • discuss.answer
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          For 10 years I've been complaining about this. These aren't "template" variables, they have nothing to do with templates. That was just a convenient way to categorize resources to be able to assign the "extended resource fields" to something. I have always thought that resources should have been given categories, as elements were, and the extended resource fields assigned by category, if not by individual resource. The way it works, it leads to a multiplicity of templates that serve no purpose except to control TVs.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org