We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27672
    • 168 Posts
    can the @DOCUMENT binding only be used within a TV?

    here’s what i’m looking to do: have a resource "menu", which we’ll say has an id of 10. in the template i’d like to include this document in the navigation area. the manager user i would like to edit this menu will not have access to edit any elements (chunks, templates, snippets, tvs, etc), but would have permissions to edit resource #10

    is there a way to call "@DOCUMENT 10" in just one place? like call it directly from within a template, or a chunk? or does it need to be created as a TV? and then maybe hide that tv from the non-admin manager users?
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      YOu can do this with a snippet as follows:

      New Snippet, name it something like ’getContent’:
      <?php
      $doc = ($docID) ? $docID : 10; //Check if the &docID parameter is set, if not use 10 as default.
      $docData = $modx->getDocument($doc, '*', 0); // This searches for unpublished documents with an ID of $doc. To search for published, change the 0 into a 1.
      if (empty($docData)) { return 'Uh oh... document not found!'; }
      return $docData['content'];
      ?>


      Call in your template:
      [tt][[getContent]][/tt] or [tt][[getContent? &docID=`13`]][/tt] to get the content.

        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You can also use a TV. TVs can be assigned to document groups just as resources can, so they would be hidden from a manager user not assigned to the associated manager user group.
          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
          You probably know this, but just in case: The Wayfinder snippet will create a menu for you and will update it automatically when new documents are created.
            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
            • 27672
            • 168 Posts
            indeed. this is actually just for a collection of "handy" links (to other domains) that appear below the normal site navigation in a sidebar. so they’re completely arbitrary links, and thus not wayfinderable smiley

            the people who might need to edit this list are not necessarily people who could be trusted in the elements tab.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              However, you could use Jot for this. Put a simple Jot snippet on a page just for this, with the minimum configuration to only allow Manager users to post. Minimize the form tpl to just have two input fields, one for the link text and the second for the URL. Have a simple comment tpl to make a list item with the link. Then where you want the menu to be displayed, use ul tags to enclose a Jot snippet with no form.

              Your editor can go to this page (it can even be unpublished, since manager users can see unpublished pages) and add/edit the links to his heart’s content. I’ve even added an AJAX drag-and-drop script to such a page so the editor can reorganize his list, using the "parent" field in the table for the position, since it isn’t used for anything else now.
                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
                • 27672
                • 168 Posts
                However, you could use Jot for this. Put a simple Jot snippet on a page just for this, with the minimum configuration to only allow Manager users to post. Minimize the form tpl to just have two input fields, on for the link text and the second for the URL. Have a simple comment tpl to make a list item with the link. Then where you want the menu to be displayed, use ul tags to enclose a Jot snippet with no form.
                
                Your editor can go to this page (it can even be unpublished, since manager users can see unpublished pages) and add/edit the links to his heart's content. I've even added an AJAX drag-and-drop script to such a page so the editor can reorganize his list, using the "parent" field in the table for the position, since it isn't used for anything else now.


                thanks for the advice, i’ll have to check out jot, as i have never really used it, but for this case the @DOCUMENT binding in a tv hidden from non-admins works perfectly, was very fast to implement, and it’s one of those things i have a feeling no one will actually use, but it was pertinent that the ability was there... heh. i’m sure every developer knows exactly what i mean by that. wink
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  The only reason I mentioned the Jot option was because having users edit a page full of links could become a disaster, while filling out two fields in a form is much simpler.
                    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
                    • 27672
                    • 168 Posts
                    i agree, but right now that "page full of links" is... 2 links, and i’m thinking maybe someday it might get up to 3, or maybe even 4. haha. it’s always so hard to explain exactly what you’re doing in a brief forum post. in this case, it really won’t be used, so being as "static" as possible is probably best.

                    as always, thanks for your advice everyone!
                      • 3749
                      • 24,544 Posts
                      Quote from: slush at Jul 15, 2010, 08:05 AM

                      i agree, but right now that "page full of links" is... 2 links, and i’m thinking maybe someday it might get up to 3, or maybe even 4. haha. it’s always so hard to explain exactly what you’re doing in a brief forum post. in this case, it really won’t be used, so being as "static" as possible is probably best.

                      as always, thanks for your advice everyone!

                      In that case, I’d just have the users email me the link and link text and do it myself. I think it would take less of your time in the long run.

                      For a longer list, I’d create a form to submit for adding new links and link text.
                        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