We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17883
    • 1,039 Posts
    Quote from: MadeMyDay at Jul 17, 2006, 11:48 AM

    Added to the tracker:

    FS#464 — TV value @inherit has to look for parent value

    ;)
      • 10487 MODX Staff
      • 1,535 Posts
      Lol ... you must’ve have posted it while I was driving home from work laugh I’ll learn to scroll up next time rolleyes
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 34162
        • 1 Posts
        An interesting aspect is how the renderer can work correctly while the api doesn’t.
        They obviously use different procedures or different sequences of the same procedures to access TV values. Strange.
        I argue that the API is derived from the renderer and not vice versa. For me this is the only explanation for this behaviour and bug-fixing is difficult under these circumstances. But as soon as we have 1.0 we can forget about all this stuff grin


          • 24292
          • 28 Posts
          Looking at getTemplateVarOutpu in document.parser.inc.php, I think this may be a clue.
                    // to-do needs fixing when getting tvs from other pages
            • 10487 MODX Staff
            • 1,535 Posts
            Okay, this is strange. huh

            I just had a spare five minutes and thought I’d give this a proper test. With the example that grad gave in the first post, it works fine. Using getTemplateVarOutput(), the template variable value is inherited as it should from the parent document.

            I’ll try a few more test cases and see if I can replicate the bug ...

            @grad: Just a question, is the code you used part of a snippet? If so, did you call it uncached? ie. using [!snippet!]
              Garry Nutting
              Senior Developer
              MODX, LLC

              Email: [email protected]
              Twitter: @garryn
              Web: modx.com
              • 36541
              • 222 Posts
              @garryn: Yes, it is a part of a snippet. Actually I came on this issue when working on getField. I defined function to get a value from a template variable:

              <?php
              function getTV($modx,$docid,$doctv)
              {
              	$output = $modx->getTemplateVarOutput($doctv,$docid);
              	return $output[$doctv];
              }
              ?>

              For testing purposes I created a simple ’test_tv’ of text type (’@INHERIT test’), a test snippet and a test document with uncashed call:

              [!test!]


              Then I overwrote the value of ’test_tv’ with other value and checked the output for diffrent child documents with:

              <?php
              $output = getTV($modx,42,'test_tv');
              print_r($output);
              ?>

              For each document tested it returned the overwritten value or the default value. Never the inherited one. Then I posted this question. And after that reworked ’getTV’ function to get inherited value of tv.
                This is the web: the only thing you know about who will come is that you don't know who will come.
                • 17883
                • 1,039 Posts
                I just tried that with rev1417 (0.95beta2). Seems to work now?

                I created a TV "test", text with standard value "@inherit hello world".

                site structure:

                doc1
                -- doc 2
                ----doc 3

                snippet "test":

                <?php
                $docid=$modx->documentIdentifier;
                $output = $modx->getTemplateVarOutput('test',$docid);
                return $output['test'];
                ?>


                Content of pages:

                This is renderer output: [*test*]
                <br><br><br>
                This is API Output: [!test!]
                


                Result: On all pages the same, no matter which changes I made to the TV value on the pages or the TV settings in the manager. Can someone confirm?
                  • 36541
                  • 222 Posts
                  I recreated the test carried out by Marc (MadeMyDay) but with revision 2051 and I got the same results. Then I modified it to test the original problem, which was returning the value of template variable for another document. Not the current one! It turned out that the original problem persists.

                  The test


                  I made a simple hierarchy with clean install of rev. 2051 (numbers in parentheses are document ids):

                  Doc 1 (1)
                  + Doc 2 (2)
                    + Doc 3 (3)


                  I added a template variable named [tt]inherit[/tt], text, empty, with default value [tt]@INHERIT Hello world[/tt]. Then made a snippet with the same original name [tt]inherit[/tt] wink :

                  <?php
                  $docid = 2;
                  $output = $modx->getTemplateVarOutput( 'inherit', $docid );
                  return $output[ 'inherit' ];
                  ?>


                  All documents have the same content:

                  <p>Renderer output: [*inherit*]</p>
                  <p>API Output: [!inherit!]</p>


                  Results



                  • With no overrides to tv values, both renderer and API results are the same, which is what one would expect.

                  • With value for [tt]Doc 1[/tt] overridden with [tt]override[/tt]:
                    [table]
                    [tr][td]Document[/td][td]Renderer[/td][td]API[/td][/tr]
                    [tr][td]Doc 1[/td][td][tt]override[/tt][/td][td][tt]Hello world[/tt][/td][/tr]
                    [tr][td]Doc 2[/td][td][tt]override[/tt][/td][td][tt]override[/tt][/td][/tr]
                    [tr][td]Doc 3[/td][td][tt]override[/tt][/td][td][tt]override[/tt][/td][/tr]
                    [/table]
                    Error: value for [tt]Doc 1[/tt] should be [tt]override[/tt].

                  • With value for [tt]Doc 2[/tt] overridden with [tt]override[/tt]:
                    [table]
                    [tr][td]Document[/td][td]Renderer[/td][td]API[/td][/tr]
                    [tr][td]Doc 1[/td][td][tt]Hello world[/tt][/td][td][tt]override[/tt][/td][/tr]
                    [tr][td]Doc 2[/td][td][tt]override[/tt][/td][td][tt]override[/tt][/td][/tr]
                    [tr][td]Doc 3[/td][td][tt]override[/tt][/td][td][tt]override[/tt][/td][/tr]
                    [/table]
                    OK.

                  • With value for [tt]Doc 3[/tt] overridden with [tt]override[/tt]:
                    [table]
                    [tr][td]Document[/td][td]Renderer[/td][td]API[/td][/tr]
                    [tr][td]Doc 1[/td][td][tt]Hello world[/tt][/td][td][tt]Hello world[/tt][/td][/tr]
                    [tr][td]Doc 2[/td][td][tt]Hello world[/tt][/td][td][tt]Hello world[/tt][/td][/tr]
                    [tr][td]Doc 3[/td][td][tt]override[/tt][/td][td][tt]Hello world[/tt][/td][/tr]
                    [/table]
                    OK.

                  Conclusion

                  The [tt]getTemplateVarOutput[/tt] function does not return inherited value for a template variable when called from another document.

                  I made a comment in the associated bug tracker task.
                    This is the web: the only thing you know about who will come is that you don't know who will come.
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Guys, there is a misunderstanding brewing here, and its likely caused by the API itself; the method being called getTemplateVarOutput is confusing, at it only gets raw values. Getting the value of a TV is NOT the same as rendering the output of a TV. To get the inherited values, you must process the TV, not just get the specific document value. Getting the value just returns the raw value, period. The @ bindings are only evaluated when a TV is processed.
                      • 36541
                      • 222 Posts
                      Quote from: OpenGeek at Nov 24, 2006, 12:36 PM

                      To get the inherited values, you must process the TV, not just get the specific document value. Getting the value just returns the raw value, period. The @ bindings are only evaluated when a TV is processed.

                      How to process a template variable using API, then?

                      BTW, how to process a chunk using API? [tt]getChunk[/tt] method gets the raw chunk content.
                        This is the web: the only thing you know about who will come is that you don't know who will come.