We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21484
    • 23 Posts
    Why does this statement returns no value if I use it in the Default Value or Option Values field for an tv?

    I also get no value if I try to get the value with a snippet call in a chunk bind with @CHUNK to an tv.

    @CHUNK my_chunk
    
    [[my_snippet]]
    
    <?php
    return $id;
    // or
    return $modx->resource->get('id');
    // ...
    


    Is there no posibility to get the current resource id in this context?
      • 5340
      • 1,624 Posts
      Just guessing here but shouldn’t it be:

      @EVAL return $modx->resource->get('id');


      I think you are trying to eval php, in a chunk binding. @CHUNK should be use if you already have a Chunk
        • 21484
        • 23 Posts
        Look at the subject of this topic: @EVAL return $id;

        This is exactly what not works.

        The code above is only an alternative way that also not works.
          • 5340
          • 1,624 Posts
          Works for me. Screen shot attached

          Make sure your tv is attached to the correct template and [[*TEST]] is present in your template.
            • 21484
            • 23 Posts
            Thanks cipa.

            Unfortunately it doesn´t work for me. If I use it this way, the manager runs into a never ending loading of the resource.
            There must be an other reason for this behaviour I couldn´t find out yet.


            Yes, it works in the Frontend. I get the value there.
            But if I use it this way, the manager runs into a never ending loading of this resource.
            And secondly what I want is the id available in the manager tv field and not only after rendering for the frontend. It is the base to built a DropDown List with values from other resources. Because it depends on the resource parent I can not work with static ids.

            Example:
            @EVAL return $modx->resource->get('parent') .'==a';

            This is the base I need to get other values depends on the parent element...
              • 28215
              • 4,149 Posts
              I think this happens because $modx->resource isn’t available to the TV in the mgr instance. This has been fixed here: http://github.com/modxcms/revolution/commit/b05d3927d106479f44d9c2a19d05ed01162e22a7
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 21484
                • 23 Posts
                Yeah. Big thanks to splittingred. This was exactly the problem.
                  • 21484
                  • 23 Posts
                  Damn. There goes something more wrong with this.

                  After doing the fix above I always get the id=1 for the current resource.

                  @EVAL return $modx->resource->get('id');