We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39827
    • 42 Posts
    I got a project and a lot of pages (same template) must be filled with same content each time. (its a section of a person. I want to show his adress, name, etc... in each child page)
    At this moment i use fastfield snippet like this. (combined with Ultimateparent)

    <p>[[#[[UltimateParent? &topLevel=`4`]].tv.ra_adres]] [[#[[UltimateParent? &topLevel=`4`]].tv.ra_huisnummer]]<br/>
    		[[#[[UltimateParent? &topLevel=`4`]].tv.ra_postcode]] [[#[[UltimateParent? &topLevel=`4`]].tv.ra_woonplaats]]<br/>
    		[[#[[UltimateParent? &topLevel=`4`]].tv.ra_telefoon]]<br/>
    		</p>


    Is it better to use GetResources in this case?
    Or a plain php script snippet?

    The fastest option seems best to me.
      • 42046
      • 436 Posts
      ClientConfig should be faster than using tvs for the information.

      http://modx.com/extras/package/clientconfig
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        All of those UltimateParent snippets will indeed be slow.

        If I understand correctly, you have container/parent resources for people, and you want the information from that container/parent resource to be displayed on that resource's children. I would use another TV, with @INHERIT binding, and in each parent resource put the ID of that parent. Then you could have
        [[#[[*parentId]].tv.ra_adres]] etc. 

        which would be much faster than running the UltimateParent snippet for each one.

        Don't name your TV "parent", since that would conflict with the regular [[*parent]] field.
          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
          • 3749
          • 24,544 Posts
          Since @INHERIT will get the first ancestor with the TV set, you could also set the values in the ultimate parent, use @INHERIT for all TV values below that, and just do this:

          <p>[[*tv.ra_adres]] [[*tv.ra_huisnummer]]<br/>
                  [[*tv.ra_postcode]] [[*tv.ra_woonplaats]]<br/>
                  [[*tv.ra_telefoon]]<br/>
                  </p>
          


          I think Susan's method would be faster, though.

          The fastest way I can think of would be to write a plugin that saves the whole formatted string of personal information to a single TV, a chunk, or (fastest of all) the introtext or description fields whenever you save a child resource.

          Something like this:

          /* Get the ultimate parent object */
          $upId = (int) $modx->runSnippet('UltimateParent', array('id'=>$resource->get('id'), 'topLevel' => '4'));
          $upObj = $modx->getObject('modResource', $upId);
          
          /* Save the string to the 'description' 
             field of the current resource */
          if ($upObj) {
              $output = '<p>' . $upObj->getTVValue('tv.ra_adres') . ' ' . $upObj->getTVValue('tv.ra_hiusnummer') . 
                  '<br/>' . $upObj->getTVValue('tv.ra_postcode') . ' ' . $upObj->getTVValue('tv.ra_woonplaats') . '
                   <br/>' . $upObj->getTVValue('tv.ra_telefoon');
              $resource->set('description', $output;)
              $resource->save();
          }
          
          return '';
          



          Now you can display your information on any page in a flash by just putting this where you want the info:

          [[*description]]


          Best of all, it will be cached with the page, so it should take no time at all once the cached page exists.




            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
            • 39827
            • 42 Posts
            Thank you very much for the fast and mutiple answers. I will use the @INHERIT solution.
            I got 1 question about @INHERIT. How fast is it. Its a function like Ultimateparent that crawls up the tree to find the first filled TV. (i think it works like that)


            The pluginn Bob sugest is great, but has 1 disadvance i guess. If the client gets an other adress he/she must update (open and save) all childpages.
            (The parent and the child pages all use the same template. Otherwise i could put @INHERIT in the *descriptionfield)
            But the idea gives me a solution for an other website.
              • 42046
              • 436 Posts
              If the client gets an other adress he/she must update (open and save) all childpages.

              That's one reason why I suggested ClientConfig, it's designed for the exact problem you have here.
                • 39827
                • 42 Posts
                Quote from: absent42 at Nov 03, 2014, 05:25 AM
                If the client gets an other adress he/she must update (open and save) all childpages.

                That's one reason why I suggested ClientConfig, it's designed for the exact problem you have here.

                I will try it out thanks for the advise