We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49324
    • 14 Posts
    Hello, i am trying to pass a parameter to a template variable of a different resource but i am (probably) missing something.

    Consider i have these 2 templates:
    page1 (id:1)
    page2 (id:2)

    in page1 i want to call a template variable that is inside page2 and pass it a parameter. I am using fastField.

    So in page1 i have the following code
    [[#2.tv.tvName?parameterName=`parameterValue`]]


    while in page2 i have the template variable tvName that simply calls the parameter as follows
    parameter value is: [[!+parameterName]]


    The problem is that in page1 i see only the static text "parameter value is: " from tvName of page2 without the parameter value passed from page1...
    Hope you can help, thank you very much.

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

      • 3749
      • 24,544 Posts
      Is the placeholder in the TV itself, or on page2?

      I haven't looked at the code, but AFAIK, FastField does not take properties. My guess is that it's ignoring everything after tvName.














        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
        • 49324
        • 14 Posts
        Hello Bob and thanks for your reply. The placeholder is in the TV itself.
        If FastField is really ignoring the property, do you have any clue on how i could achieve what i am looking for?
        • discuss.answer
          • 3749
          • 24,544 Posts
          I think it would take a custom snippet (the first ## would be the TV ID, the second ## would be the ID of resource2):

          [[!ShowTV? &tvId=`##` &resourceId=`##` &ph=`placholderName` &pv=`placeholderValue`]]


          /* ShowTV snippet */
          $sp= $scriptProperties;
          $tv = $modx->getObject('modTemplateVar', (int) $sp['tvId']);
          
          if ($tv) {
              $value = $tv->getValue($sp['resourceId'];
              $output = str_replace('[[+' . $sp['ph'] . ']]', $sp['pv'], $value);
          } else {
             $output = 'TV not found';
          }
          
          return $output;


            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
            • 49324
            • 14 Posts
            But by getting the template variable this way (with it's id) i am not getting the TV as it is defined inside the template/resource.

            I mean that if the TV id is (10) while the id of the resource where it is defined is (2) by doing this
            [[#2.tv.tvName]]

            and this in a snippet
            $tv = $modx->getObject('modTemplateVar', (int) 10);


            i am not getting the same result...correct?
              • 3749
              • 24,544 Posts
              I'm not sure I understand your question, but the snippet should replace the placeholder and FastField won't.
                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
                • 49324
                • 14 Posts
                Sorry Bob after thinking a little bit, i used just the str_replace function from your snippet to achieve what i wanted and now it is working as expected!
                Your solution was obviously working but was not giving me what i was looking for, my fault in posting the question.
                You managed to give an answer to it anyway: thanks!!
                  • 3749
                  • 24,544 Posts
                  I'm glad you got it sorted. smiley
                    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