We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48042
    • 5 Posts
    I am using TV input option exactly like this http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/template-variable-input-types#TemplateVariableInputTypes-MoreAdvancedUsage
    @SELECT pagetitle, id FROM modx_site_content WHERE parent=35

    ...and there is no problem.

    But what about when I want to load resources based on Context Settings or just placeholder?

    For example [[++shop]] is my Context Setting with (context specific) parent ID.
    So then I want to use something like this
    @SELECT pagetitle, id FROM modx_site_content WHERE parent=[[++shop]]

    And... it doesn't work. Is there any other way? Or?

    Thanks a lot
      • 3749
      • 24,544 Posts
      It's not clear to me what you're trying to do. TV's are meant to have a different value for each Resource and are generally slow when used to select resources. If all the TVs are going to have the same value, you probably don't want a TV for the job.

      I think you might be better off with a snippet, which could get the Setting much faster than the tag could be parsed (even if that were possible). Something like this:

      /* get setting */
      $shop = $modx->getOption('shop');
      
      /* get resources */
      $resources = $modx->getCollection('modResource', array('parent' => $shop));
      
      /* create and return output */
      $output = '';
      
      foreach($resources as $resource) {
         $output .= '<br />Pagetitle: ' . $resource->get('pagetitle') . ' ID: ' . $resource->get('id');
      }
      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
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        He's trying to generate a list to select from in the TV when editing a resource, Bob. This is using @SELECT in the "input options" field.
          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
          • 3749
          • 24,544 Posts
          Doh. In that case, ignore the code in my response. You might be able to use a plugin attached to OnDocFormPrerender. I'm not sure it would work and if the Resource gets saved, the Setting value would replace the tag.

          I guess you could also do it with an @EVAL TV, but it wouldn't be pretty. wink The code would look something like my code above, but with "||" and "==" tokens in the output.

          Maybe something like this (all on one line):

          @EVAL $resources = $modx->getCollection('modResource', array('parent' => $modx->getOption('shop')));
          foreach($resources as $resource) {
             temp[]= $resource->get('pagetitle') . '==' . $resource->get('id');
          }
          return implode('||', $temp;

            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
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Can the @SELECT binding accept joins in the query?
              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
              • 3749
              • 24,544 Posts
              I kind of doubt it, but I could be wrong.

              This probably won't work either, but it's a thought:

              @SELECT pagetitle, id FROM modx_site_content WHERE parent=@EVAL return $modx->getOption('shop');
                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
                • 48042
                • 5 Posts
                Hi Bob, it is exactly how I am trying to do it, but it seems modx can't get any context settings and even document id on this place.

                For example something like that in TV input option doesn't work.
                @EVAL return $modx->resource->get('id');
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  what happens if you add "global $modx;" to that?
                  @EVAL global $modx; return $modx->resource->get('id');

                    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
                    • 48042
                    • 5 Posts
                    Yes it works with global, thanks! smiley But still not work with $modx->getOption('shop');.
                    Maybe solution could be something like that? (written in hurry)
                    1. get documentId $modx->resource->get('id');
                    2. run some snippet to get context of documentId (I don't know how)
                    3. get context settings $shop $modx->getOption('shop');
                    4. runSnippet geResources parents=$shop

                    What do you think? smiley It seems hard way how to reach easy goal smiley [ed. note: noobie last edited this post 12 years, 3 months ago.]
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      getOption gets a system setting.
                        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