We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30497
    • 245 Posts
    I have a series of webpages where I use the @DOCUMENT binding to call other documents into the webpage. Now, in this example...
    @DOCUMENT 107

    ...I call the [*content*] section of my document with an id of 107, into the new webpage.

    What I would also like to do is call the [*longtitle*] (or pagetitle, or any other document-specific variable) of 107 into the new webpage.


    Can I use @bindings to achieve this? If so, how?

      • 26931
      • 2,314 Posts
      Hi!

      i think you can do that with the getField-Snippet -> http://modxcms.com/getField-667.html

      j
        • 30497
        • 245 Posts
        Quote from: sharkbait at Feb 22, 2009, 06:34 AM

        Hi!

        i think you can do that with the getField-Snippet -> http://modxcms.com/getField-667.html

        j

        Thanks! Just because that snippet seems a bit old, I wonder if it is possible to do this with MODx "as is".
          • 26931
          • 2,314 Posts
          Hi,

          last post in the support-thread is from 23rd dec 08, so i guess you should be fine smiley
          maybe try it with an MODx test-instrallation first...

          support-thread -> http://modxcms.com/forums/index.php/topic,5643.45.html

          j
            • 33337
            • 3,975 Posts
            I use getField in my day to day work, its safe to go ahead with it.
              Zaigham R - MODX Professional | Skype | Email | Twitter

              Digging the interwebs for #MODX gems and bringing it to you. modx.link
              • 9207 ☆ A M B ☆
              • 2,475 Posts
              I’d say that you’re better off with a Snippet anyway... the @Bindings aren’t well documented... I posted a whole bunch of pages in the Wiki after numerous experiments with them. My conclusion is that they’re great for common tasks, but anything that breaks out of their mold should be done with a Snippet... it’ll be more clear that way.
                • 3749
                • 24,544 Posts
                If you’re getting multiple document objects, I think you’ll want a snippet and a tpl chunk. It will give you much better control and flexibility.

                The Tpl chunk (let’s call it MyTplChunk) will hold the placeholders for the things you want and the snippet (let’s call it MySnippet) will get the document info, set the placeholders, and return the Tpl chunk:

                MyTplChunk:

                <h2>[+MyLongTitle+]</h2>
                <h3>[+MyAlias+]</h3>
                <div class="content">[+MyContent+]</div>


                Snippet code:

                
                $id = $pageId;  // sent in snippet call
                
                $fields = 'longtitle,alias,content'; // fields we want
                $active = 1; // we want published docs
                
                $info = $modx->getPageInfo($id, $active, $fields); 
                
                
                $longTitle = $info['longtitle']; 
                $docAlias = $info['alias'];
                $docContent = $info['content'];
                
                
                $modx->setPlaceholder('MyLongTitle',$longTitle);
                $modx->setPlaceholder('MyAlias',$docAlias);
                $modx->setPlaceholder('MyContent',$docContent);
                
                
                return($modx->getChunk('MyTplChunk');


                In your document:

                [!MySnippet? &pageId=`21`!]


                Be careful of the spellings, everything is case-sensitive. smiley

                  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
                  • 30497
                  • 245 Posts
                  Hi Bob,

                  Thanks for your help. I tried using your code here, and I couldn’t get it to work. I am not a php programmer, so I am not sure how to troubleshoot. I tried using my own edits to your code, and when that didn’t work, I tried your own code directly. Here is what I did:

                  I created a chunk called "getFieldsTemplate":
                  <h2>[+tipTitle+]</h2>
                  <p>[+tipContent+]</p>
                  


                  I created a snippet called "getFields":
                  <?php
                  $id = $pageId;  // sent in snippet call
                  
                  $fields = 'longtitle,content'; // fields we want
                  $active = 1; // we want published docs
                  
                  $info = $modx->getPageInfo($id, $active, $fields); 
                  
                  $longTitle = $info['longtitle']; 
                  $docContent = $info['content'];
                  
                  $modx->setPlaceholder('tipTitle',$longTitle);
                  $modx->setPlaceholder('tipContent',$docContent);
                  ?>
                  


                  I inserted my snippet call into a TV on one of my pages:
                  [!getFields?&tpl=`getFieldsTemplate`&pageId=`108`!]
                  


                  But nothing is printed to the page. I will try the "getField" snippet that was mentioned earlier int he thread, but I wanted to try your solution here first.


                    • 9207 ☆ A M B ☆
                    • 2,475 Posts
                    Looks like you need to return the output from your Snippet. I think Bob may have left that part out...

                    Try adding the following to the last line of your Snippet:

                    return 'Testing...';


                    And then see if you see anything when you view the page. If you do, then you know your Snippet is executing and making it through to the end. If you don’t see anything, you know there’s a problem somewhere above.

                    In my Snippets, I use something like this:

                    $output=$modx->parseChunk( $tpl, $row, '[+', '+]');
                    return $output


                    Where $row represents a row from a database query... but you can see how the Snippet must act like a function and return results.
                      • 3749
                      • 24,544 Posts
                      Quote from: Everett at Feb 24, 2009, 10:44 AM

                      Looks like you need to return the output from your Snippet. I think Bob may have left that part out...

                      I didn’t, but he did. wink

                      You have to scroll down to see all the code in my snippet example above, you left out this crucial line at the end of the snippet:

                      return($modx->getChunk('MyTplChunk');
                        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