We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4757
    • 64 Posts
    I’m attempting to add an sidebar that shows content related to the currently viewed page, based on tags. For example, if the current page has a tag in a TV of "Test" then I want to see a list of resources that also include the tag of "Test". I’ve setup the TV and assigned tags to a couple pages to test it out and I’m not getting any results back.

    Here is how I am making the call:
    [[!getResourcesTag?
      &parents=`[[UltimateParent]]`
      &resources=`-[[*id]]`
      &depth=`10`
      &includeContent=`0`
      &includeTVs=`1`
      &showHidden=`0`
      &hideContainers=`0`
      &elementClass=`modSnippet`
      &element=`getResources`
      &toPlaceholder=`results`
    ]]


    Any ideas on where I’m going wrong?
      • 22019
      • 390 Posts
      You haven’t defined a template for display. I’d also move the &element and &elementclass params to the top, as sometimes add-ons can be picky about the order of parameters.
        Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
        • 4757
        • 64 Posts
        ok, so I added a template for the results to display in, and still nothing. This is my updated call and the chunk for the tpl.
        [[!getResourcesTag?
          &elementClass=`modSnippet`
          &element=`getResources`
          &parents=`[[UltimateParent]]`
          &resources=`-[[*id]]`
          &depth=`10`
          &includeContent=`0`
          &includeTVs=`1`
          &showHidden=`0`
          &hideContainers=`0`
          &tpl=`relatedContentItem`
          &toPlaceholder=`results`
        ]]

        <li><a href="[[~[[*id]]]]">[[*pageTitle]]</a></li>


        The place holder "results" is in another chunk with the following:
        <div id="related">
           <h4 class="light">Related</h4>
            <ul>
            [[+results]]
            </ul>
        </div><!--close related-->
          • 3749
          • 24,544 Posts
          Change the Tpl chunk to this:

          <li><a href="[[~[[+id]]]]">[[+pageTitle]]</a></li>


          and make sure you have a [[$ChunkName]] tag in the resource with the getResources tag or you won’t see any results.

          When setting up a new snippet call, it’s best not to try to do everything at once, so you might consider just taking the &toPlaceholder parameter out for now, simplifying &parents, and putting this in the Resource Content field:


          <div id="related">
             <h4 class="light">Related</h4>
              <ul>
             [[!getResourcesTag?
            &elementClass=`modSnippet`
            &element=`getResources`
            &parents=`0`
            &depth=`10`
            &includeContent=`0`
            &includeTVs=`1`
            &showHidden=`0`
            &hideContainers=`0`
            &tpl=`relatedContentItem`
          ]]
              </ul>
          </div><!--close related-->
          
          
          
            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
            • 4757
            • 64 Posts
            ok we’re making progress. I took your advice and stripped everything out and started with a simple getResources call with a display tpl. I’m getting the results I should be.
            I then made the basic [[getResources]] into a [[getResourcesTag]] to begin to get the results that I actually want, but I’m still getting the same results as the basic [[getResources]] call. This is what everything looks like now.
            <div id="related">
               <h4 class="light">Related</h4>
                <ul>[[!getResourcesTag? &elementClass=`modSnippet` &element=`getResources` &tpl=`relatedContentItem` &parents=`0` &limit=`5` &tagKey=`tags` &includeContent=`0`]]</ul>
            </div><!--close related-->


            my template chunk for relatedContentItem is
            <li><a href="[[~[[+id]]]]">[[+pagetitle]]</a></li>


            maybe I setup my tags TV incorrectly... I have it as text input and a default output and the TV is named "tags". There is a "tags" input option for the TV, should I be using that?
              • 22019
              • 390 Posts
              I may be getting the wrong end of the stick here, but I don’t think you’re setting a condition at all - at present you’re just asking it to return all resources that have the ’tags’ field populated.

              (To answer your other question, afaik, the tags input option is simply a speedier way of getting text into that field - at a base level they’re both text input fields. However, it is pretty nifty, and I use it on keywords style fields, where you want to keep consistency, but don’t need the rigour of a list).
                Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
                • 3749
                • 24,544 Posts
                What you’re trying to do is fairly complex for a beginning MODx user. The getResourcesTag snippet calls the getPage snippet (for pagination), which in turn calls the getResources snippet.

                I’ve never used this, but it appears that the tag you want to show must be sent in as a $_GET variable, either in the URL of the page with the getResourcesTag tag or from a form that posts to that page using the "get" method. I believe your snippet tag is correct, though. When getResources doesn’t understand the search criteria or they are missing, it tends to show every resource under the &parents that’s published and not hidden from menus.
                  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
                  • 4757
                  • 64 Posts
                  Ok, we’re getting somewhere here. Thanks so much for your patience. There is an example in the Documentation that looks like this:

                  Display Resources with tag ’test’ (found in the GET param ’tag’) in the TV ’blog-tags’, and set the results to a placeholder called ’results’:

                  [[!getResourcesTag? &parents=`4,12,33` &tagKey=`blog-tags` &toPlaceholder=`results`]]

                  <h2>Search Results</h2>

                  [[!+results]]

                  As a beginner and not a programer at all, what does "(found in the GET param ’tag’)" mean and how do I do that? This is exactly what I want to do, but on page load and not after clicking an a list of tags.
                    • 22019
                    • 390 Posts
                    Bob may know better, but it sounds like in that example a url ending in ?tags=test would look for the value ’test’ in the tv ’blog-tags’.

                      Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
                      • 3749
                      • 24,544 Posts
                      Quote from: odeclas at Feb 02, 2011, 02:13 PM

                      Bob may know better, but it sounds like in that example a url ending in ?tags=test would look for the value ’test’ in the tv ’blog-tags’.

                      That should work, but every page with a link to the current page would have to have that special URL.

                      If might work to put a snippet call at the top of the page (above the getResourcesTag tag) like this:
                      [[!SetTag]]


                      /* SetTag snippet code */
                      $_GET['tags']='test';
                      return '';
                      


                      As I say, I’ve never used that snippet so I’m guessing here and there may be an easier way.
                        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