We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25551 ☆ A M B ☆
    • 1,231 Posts
    Hello,

    I have a TV using the @SELECT binding and wondered how I can use the current ID as the parent ID?

    I have tried the following ways and it does not work, I wonder if someone can shed light on this. I did wrap the $_REQUEST[’id’] with ’. .’ as well.

    @SELECT `pagetitle`,`id` FROM `[[+PREFIX]]site_content` WHERE `parent` = $_REQUEST['id'] AND `published` = 1


    @SELECT `pagetitle`,`id` FROM `[[+PREFIX]]site_content` WHERE `parent` = [[+id]] AND `published` = 1


    @SELECT `pagetitle`,`id` FROM `[[+PREFIX]]site_content` WHERE `parent` = [[*id]] AND `published` = 1


    but using this works...

    @SELECT `pagetitle`,`id` FROM `[[+PREFIX]]site_content` WHERE `parent` = 90 AND `published` = 1



    If anyone could help that would be great.

    Thanks!


      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 36493
      • 64 Posts
      Dang! this is what I want to know???

      Any ideas?

      See related post featuring alternative attempt to do the same thing:
      http://modxcms.com/forums/index.php/topic,64570.msg365268.html#msg365268
        |
        • 3749
        • 24,544 Posts
        I’m not sure how to get the ID of the current page being edited in the Manager. $_GET[’id’] used to work, but I’m not sure what does now. Did you try $scriptProperties[’id’]?
          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
          • 36493
          • 64 Posts
          Thanks for the suggestions BobRay!

          Unfortunately both do not work sad

            |
            • 33968
            • 863 Posts
            How about building your query in an @eval binding instead - using $modx->resource->get(’id’); to pull in the current docid?
            Just a guess though, not sure if that would work undecided
              • 33968
              • 863 Posts
              Or even better, you can use $modx->resource->getMany(’Children’); to get the current doc’s children, then loop through all the results, check if published, then output using the correct delimiters.

              Eg: pagetitle1==id1||pagetitle2==id2

              Might be best putting that in a snippet and executing it using @EVAL.
                • 36493
                • 64 Posts
                Thanks Lucus,

                I’ll try the $modx->resource->getMany(’Children’); method.

                See linked thread above for my previous attempt to use @eval for this purpose.
                  |
                  • 3749
                  • 24,544 Posts
                  I thought you wanted to generate the list of children for use with the TV in the Manager.

                  If you want it for the front end, a simple snippet is probably a better choice:
                  [[!ShowChildren]]

                  <?php
                  /* ShowChildren snippet */
                  
                  $children = $modx->resource->getMany('Children');
                  
                  $output = "";
                  
                  if (! empty ($children)) {
                      $output = '<ul>';
                      foreach $children as $child) {
                          $output .= '<li>' . $child->get('pagetitle') . '</li>'; 
                      }
                      $output = '</ul>';
                  } 
                  
                  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
                    • 36493
                    • 64 Posts
                    Hi BobRay,

                    No you were right, I do wish to list children in the manager. (just testing the snippets in the front end when they didn’t work in the backend)

                    Now have a working solution grin:

                    snippet called from Input Option Values: using "@EVAL return $modx->runSnippet(’listchildren’);"
                    <?php
                    $children = $modx->resource->getMany('Children');
                      $output = '';
                      
                      $list = array();
                      foreach($children as $child)
                      {
                    //check if correct template
                        if($child->get('published')&&$child->get('template')==21)
                        {
                          $list[]  = $child->get('pagetitle').'=='.$child->get('id');
                        }
                      }
                      
                      $output .= implode('||',$list);
                      
                      return $output;



                    Many thanks
                      |
                      • 33968
                      • 863 Posts
                      Nice!