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

    I am trying to understand the way, how @INHERIT should work for Template Variables. According to the official documentation (https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/bindings/inherit-binding), I can just set @INHERIT as the default value of a template variable definition. After that, I should be able to leave the tv field on a resource blank and it should travel up the resource tree to find a value. Also the method getTVValue() should do that.

    So far, so good. Well..there must be some difference in either my Understanding or the way how it is implemented.

    The way, how it works on my local instance (ModX 2.4.2):

    I created a TV language and set its default Value to @INHERIT. After that, I set the TV Value on my Parent Page to en. After that, when I create a new Child Resource, the tv on that Child Resource automatically get's filled by the Value of the parent page TV. Now, when I delete the automatically filled Value of the tv of the child page and check on the output in the fronted, nothing gets outputted. Same for when I use the Method getTVValue(), the output is just empty. So it seems, that the inheritance is only working upon creation of a new child Resource and just the other way around than the documentation would tell you..

    I googled around, but there is not much around this @INHERIT Functionality to find.. The only thing I found is this wiki page (http://wiki.modxcms.com/index.php/@INHERIT_Binding) dating July 2009, which says, that the Inheritance only happens upon creation of the child page (Exactly the behaviour, I am experiencing..)

    Does anybody know, how that @INHERIT Feature is supposed to work?

    Best Regards
    Jan

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

    • discuss.answer
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The child will inherit the value of its parent. However, once you set a value for a child, it loses that ability. If you give the child a value then delete it, you still have the value of an empty string, not no value at all.

      Until a resource's TV is given a value, a row for it does not exist in the site_tmplvar_contentvalues table for that TV and that resource. Once a value has been set, then it has a row, whether its value is empty or not.

        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
        • 50816
        • 12 Posts
        Quote from: sottwell at Dec 10, 2015, 11:40 AM
        The child will inherit the value of its parent. However, once you set a value for a child, it loses that ability. If you give the child a value then delete it, you still have the value of an empty string, not no value at all.

        Until a resource's TV is given a value, a row for it does not exist in the site_tmplvar_contentvalues table for that TV and that resource. Once a value has been set, then it has a row, whether its value is empty or not.


        OK it starts to make sense now. I would have expected the field to be blank upon initial creation of the resource, but I guess, it makes sense to show the author what will be inherited. But the thing, which really needs to be updated in the documentation, is the following sentence:


        Note that this is a dynamic lookup that occurs whenever the child page is saved and its value is empty. If you later edit the values in the parent, these will be reflected in the child. You can break the inheritance by supplying your own value in the child. You may also restore the inheritance by deleting the value and leaving the field empty.

        Because it states, you may restore the inheritance by deleting the value and leaving the field empty, which according to your post and also my trials is not true. You can only restore the inheritance (and make the entry in the site_tmplvar_contentvalues table go away) by entering the same value as the parent resource passes to the child.

        I made a GIT Request to change the documentation here: https://github.com/modxcms/docs/issues/125

        Thanks for your help.
        Best Regards
        Jan
          • 13428 ☆ A M B ☆
          • 1,031 Posts
          If you set a TV to an empty value in the backend, the row in the database is removed as far as I know. That way your code should work too.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Row is still in the database with an empty vale.
              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
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              The test involved three resources, Testing (#41) Testing Two (#42) and Testing Three (#47).

              Testing Two is the child of Testing, and Testing Three is the child of Testing Two.

              After modifying the TV value for Testing Two, both it and its child Testing Three now display that new value. A new row is added to the site_tmplvar_contentvalues.

              Upon deleting the value in Testing Two's TV, the display for Testing Two is now empty, and the row is still in the database with an empty value.

              The display for Testing Two's child reverts to the value of Testing.
                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
                • 50816
                • 12 Posts
                @scottwell, thats exactly how it is behaving on my installation. So either, the documentation, or the implementation seems to be wrong, since a field with an empty display value stays in the database with an empty string.
                  • 4172
                  • 5,888 Posts
                  it stays in the database, because an emtpy string is different from the default-value in that case, which is @INHERIT

                  the row in the db gets removed, when the value is the same like the default-value
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 50816
                    • 12 Posts
                    So I guess, the documentation should be adjusted, so that it is more clear about the fact, what happens, when you empty the field and how you restore the inherited value.. (see https://github.com/modxcms/docs/issues/125)

                    Jason Coward just pointed out, that there is a button to reset the value to the inherited one..
                    (https://github.com/modxcms/docs/issues/125#issuecomment-163922657)



                    It is the small "refresh" icon on the left side of the field, which is only displayed when hovering over the field name..