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

    Working on a site at the moment with the following structure:

    Home Country
    -- Program
    ---- Destination Country

    So, when people visit the homepage, they select their home country, for example, 'United Kingdom'. They then get into the section where they can see all the different programs. On this page, we're pulling in a template variable from the 'Home Country' which is the little flag of that country so it displays in the menu bar at the top. This helps the user see which country they're in so they know straight away that their home country is correct.

    However, if the user then clicks into a destination country, the flag in the top menu cannot be found, as it's looking for a template variable in the program page. I don't really want to have to duplicate the TV as it's more work for the client when they add new countries. So I just wondered if there was a way to pull in the top level countries TV? I could either do it in a chunk with a piece of code, or via the wayfinder, whichever is easiest, but I'm struggling to figure it out!

    Any help would be great!

    Kind regards,
    Lewis
      • 23610
      • 37 Posts
      Hi. You can make snippet for pulling TVs from different docs and use UltimateParent with it.

      Create snippet called "tv" with code:
      <?php
      // Displas any document TV on page
      $output = $modx->getTemplateVarOutput(array("$tv"),$docid="$id",$published=1);
      $output = $output[$tv];
      return $output;
      ?>

      Now if you want to get TV from top level doc while being in level 3 use this combination:
      [[tv?id=`[[UltimateParent]]`&tv=`myTvName`]]

      Did it help?
        • 42046
        • 436 Posts
          • 35150 ☆ A M B ☆
          • 191 Posts
          Hi Lewis,

          One more option for you. I've got an extra which makes this sort of thing quite simple (at least I think so smiley).
          It's called setPlaceholders and you can install it via the Package Manager.
          http://modx.com/extras/package/setplaceholders
          Documentation: https://github.com/oo12/setPlaceholders

          If you have a TV called homeCountry on a top-level resource and you want to access it from a child resource, you can use:
          [[setPlaceholders? &ph=`country == Uparent.tv.homeCountry`]]
          Then in the rest of your template and in any chunks it uses you can access the value with [[+country]]. Uparent means "ultimate parent", the top-most parent of a given resource.

          Or alternatively, this would get it from two levels up (the grandparent resource):
          [[setPlaceholders? &ph=`country == parent2.tv.homeCountry`]]
          With the site structure you described, this would be the same thing.
            Extras :: pThumb • Resizer • imageSlim • setPlaceholders
            • 17035
            • 36 Posts
            Quote from: pmfx at Mar 30, 2013, 07:44 AM
            Hi. You can make snippet for pulling TVs from different docs and use UltimateParent with it.

            Create snippet called "tv" with code:
            <!--?php
            // Displas any document TV on page
            $output = $modx--->getTemplateVarOutput(array("$tv"),$docid="$id",$published=1);
            $output = $output[$tv];
            return $output;
            ?>

            Now if you want to get TV from top level doc while being in level 3 use this combination:
            [[tv?id=`[[UltimateParent]]`&tv=`myTvName`]]

            Did it help?

            Tried this and received a Fatal PHP error for some reason. Not sure what it was causing it but thank you anyway!





            Quote from: absent42 at Mar 30, 2013, 11:53 AM
            Another option is the ShowTV add-on: http://modx.com/extras/package/showtv2

            http://bobsguides.com/showtv-tutorial.html

            This is the method I've used in the end. I used the following code in order to render it in and it now works on all levels:

            [[!ShowTv? &tvID=`9` &resourceID=`[[UltimateParent]]` &render=`1`]]








            Quote from: jgrant at Mar 30, 2013, 12:31 PM
            Hi Lewis,

            One more option for you. I've got an extra which makes this sort of thing quite simple (at least I think so smiley).
            It's called setPlaceholders and you can install it via the Package Manager.
            http://modx.com/extras/package/setplaceholders
            Documentation: https://github.com/oo12/setPlaceholders

            If you have a TV called homeCountry on a top-level resource and you want to access it from a child resource, you can use:
            [[setPlaceholders? &ph=`country == Uparent.tv.homeCountry`]]
            Then in the rest of your template and in any chunks it uses you can access the value with [[+country]]. Uparent means "ultimate parent", the top-most parent of a given resource.

            Or alternatively, this would get it from two levels up (the grandparent resource):
            [[setPlaceholders? &ph=`country == parent2.tv.homeCountry`]]
            With the site structure you described, this would be the same thing.

            I've just received this email after getting the other sections working! smiley Thank you for your message anyway, I'll look into using this option on future projects!


            Thanks for everyones help!
            Lewis
              • 23610
              • 37 Posts
              My example was for Evolution wink
                • 3749
                • 24,544 Posts
                Quote from: pmfx at Mar 30, 2013, 12:53 PM
                My example was for Evolution wink

                and

                $modx--->getTemplateVarOutput(


                should be

                $modx->getTemplateVarOutput(


                ;)
                  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
                  • 23610
                  • 37 Posts
                  BobRay, I have no idea how those additional two "-" got there.
                  Thanks for pointing it out.
                    • 3109 ☆ A M B ☆
                    • 894 Posts
                    You can use getResourceField extra for this instead of creating something custom and try to reinvent the wheel.

                    Good Luck.
                      Benjamin Marte
                      Interactive Media Developer
                      Follow Me on Twitter | Visit my site | Learn MODX
                      • 4172
                      • 5,888 Posts
                      Doesn't default-value: @INHERIT do what you want?

                      http://rtfm.modx.com/display/revolution20/INHERIT+Binding
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!