We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7527
    • 437 Posts
    Hello,
    I am having a small issue with the Tolinks snippet. On my single article page I have the following code and it outputs the tags for that page as needed:

    <div class="postmetadata">Tags: [[*tags:notempty=`[[!tolinks? &items=`[[*tags]]` &tagKey=`tags` &target=`19`]]`]]</div>
    </div>


    I then have a page which uses a 'get' call to show teasers of the latest articles:

    [[!getPage@newsPaging? &elementClass=`modSnippet` &element=`getResources` &showHidden=`1` &tpl=`newsTpl` &limit=`2` &includeContent=`1` &includeTVs=`1` &processTVs=`1` &parents=`[[*id]]` &hideContainers=`1` &pageLimit=`5` &pageNavVar=`page.nav` ]]


    Again this all works nicely along with the 'newsTpl' template code:

    <div id="post-[[+id]]" class="post-[[+id]] post hentry category-latest-news tag-tag3 tag-tag5 tag-tag7">
    <div class="post-top">
    <div class="post-date"><span class="day">[[+publishedon:strtotime:date=`%d`]]</span> <span class="month">[[+publishedon:strtotime:date=`%b`]]</span> <span class="year">[[+publishedon:strtotime:date=`%Y`]]</span></div>
    
    <h2><a title="Permanent Link to [[+pagetitle]]" href="[[~[[+id]]]]" rel="bookmark">[[+pagetitle]]</a></h2>
    </div>
    <div class="entry"><a href="[[~[[+id]]]]"><img class="alignleft" title="[[+tv.news_image_title]]" src="[[+tv.news_image]]" alt="" width="640" height="400" /></a> [[+content:ellipsis=`350`]] <a class="more-link" href="[[~[[+id]]]]">Read the rest of this entry »</a></div>
    <div class="postmetadata">Tags: [[*tags:notempty=`[[!tolinks? &items=`[[*tags]]` &tagKey=`tags` &target=`19`]]`]]</div>
    </div>


    Theis outputs the box containing the tags and a prefix of 'Tags:' but the actual tags are missing. I have looked through the tolinks info and I cannot see any parameters that may help so I am guessing its a template issue? The template code for a single article, and for the multiple article page is rather similar so I cannot figure out what is stopping my call working? Any ideas please?
      www.PawsForWildlife.co.uk
      www.Borntobrick.co.uk
      • 3749
      • 24,544 Posts
      Calling toLinks uncached (with the exclamation point), delays its processing so it's possible that its results may not be available at the time the notempty filter is processed.
        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
        • 7527
        • 437 Posts
        I tried it uncached but that changes nothing. I take it that it is either something that cannot be done or something that will require a lot of coding?
          www.PawsForWildlife.co.uk
          www.Borntobrick.co.uk
          • 3749
          • 24,544 Posts
          I think the problem is how deeply nested your code is. It's easy not to notice this, but at the very least you have a resource tag inside a snippet tag, inside a resource tag, inside a conditional output filter, inside a chunk, that's a property in a snippet tag that's inside a resource tag.

          The first thing to try (if you haven't already) is to give the notempty filter an 'else' clause at the end.

          If that doesn't work, I think I would do something like this:

          <div class="postmetadata">Tags: [[!MyTags? &tags=`[[*tags]] &target=`19`]]
          </div>
          

          /* MyTags snippet */
          
          $tags = $modx->getOption('tags', $scriptProperties, '', true);
          $target = $modx->getOption('target', $scriptProperties, '0', true);
          if (empty($tags)) {
              return '';
          }
          
          $fields = array(
              'tags' => $tags,
              'tagKey' => 'tags',
              'target' => $target,
          );
          
          return $modx->runSnippet('toLinks', $fields);
            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
            • 7527
            • 437 Posts
            Not sure how to add an else clause so tried the second option. I adjusted my call to:

            <div class="postmetadata">Tags: [[!MyTags? &tags=`[[*tags]]` &target=`19`]]</div>


            and created the snippet, but still returns blank. Thank you for the help so far
              www.PawsForWildlife.co.uk
              www.Borntobrick.co.uk
              • 3749
              • 24,544 Posts
              Let's back up. Do you have a snippet called MyTags, and where did it come from?
                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
                • 7527
                • 437 Posts
                Hi BobRay. Ok I created a new snippet and used the php code above in your post, then I named it MyTags. I then called it on my page with:

                <div class="postmetadata">Tags: [[!MyTags? &tags=`[[*tags]] &target=`19`]]
                </div>


                  www.PawsForWildlife.co.uk
                  www.Borntobrick.co.uk
                  • 3749
                  • 24,544 Posts
                  Did that work?
                    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
                    • 7527
                    • 437 Posts
                    No unfortunately not, it still returned empty
                    Regards,
                    DS
                      www.PawsForWildlife.co.uk
                      www.Borntobrick.co.uk
                      • 3749
                      • 24,544 Posts
                      Does the current page have anything in a TV called tags?
                      Is there a toLinks or tolinks snippet on the site?

                      Make sure the name, 'tolinks' in the MyTags snippet matches the tolinks snippet name exactly.
                        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