We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9849
    • 74 Posts
    Firs of all: I am still new to MODx and Ditto, so please excuse me if i’m a pain and of course for my english.
    And now welcome to another "ever wanted feature for Ditto" wink

    I tried hard to make Ditto 1.0.2 show the tags of a speciefied document ans make them links. But it seems there was no way doing this. So I took a look and found the nice Snippet TvTagCloud. But It could only archive all tags for a specified folder not only one document. So I wrote a Snippet my self. It’s very basic, thas why I’m posting it here. Maybe you like to extend it. You’re welcome to.

    What you need to do is:

    • Have a TemplateVariable(TV) which holds tags. Each tag is seperated by a delimiter (e.g. "," which is default)
    • Have a Ditto landing page (the one that lists the news)
    • Have a Ditto template(Chunk) where you can integrate the Snippet. By the way, you can integrate it where you want to. My DittoTemplate looks like this:
      <div class="ditto_summaryPost">
      <h3><a href="[~[+id+]~]">[+title+]</a> von <strong>[+author+]</strong> am [+date+]</h3>
      <div>[+summary+]</div>
      <p>[+link+]</p>
      <div>Tags: [[DocumentTVTags? &docid=`[+id+]` &TVtagsName=`tags` &sendTo=`49`]]</div>
      </div>

    Enjoy!
    /** <?php
    *  DocumentTVTags by Florian Leifeld
    *
    *  Snippet parameters [default] :
    *  &emptytext    - Text to show if no articles were found ["nicht kategorisiert"]
    *  &docid        - Show Tags for document with &docid=`x` [actual document id]
    *  &published    - Show published documents only [1]
    *  &delimiter    - Sign that delimits the TVtags [,]
    *  &TVtagsName   - Name of the TemplateVariable which holds the tags [tags]
    *  &sendTo       - ID of the tag display document (must be a Ditto document) [2]
    */
    
    $docid = isset($docid)? $docid : $modx->documentObject['id'];
    $emptytext = isset($emptytext)? $emptytext : "nicht kategorisiert";
    $published = isset($published)? $published : 1;
    $delimiter = isset($delimiter)? $delimiter : ",";
    $TVtagsName = isset($TVtagsName)? $TVtagsName : "tags";
    $sendTo = isset($sendTo)? $sendTo : 2;
    
    $TVs = $modx->getTemplateVarOutput($idname=array($TVtagsName), $docid, $published);
    if ($TVs == "") {                //<------- can someone fix it? Doesn't seem to work
      $output = $emptytext;
    }
    else {
      $output = "";
      $TVtags = explode($delimiter, $TVs[$TVtagsName]);
      foreach ($TVtags as $value) {
        $output .= "<a href='/index.php?id=".$sendTo."&tags=".$value."'>".$value."</a> ";
      }
    }
    
    echo $output;
    
      • 11975
      • 2,542 Posts
      Hi,

      I’ve faced to the same issue. You can modify TVTagCloud To operate with single doc.

      around line 89
      $subEntities = $modx->getDocumentChildren($parent);
      if(!$subEntities) $subEntities[] = $modx->getDocument($parent);//just add this line
      


      and it will render the tag value if called from a document as follow
      [[TVTagCloud? &parent=`[*id*]` ]]


      :-)
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 9849
        • 74 Posts
        Could have came up with it myself rolleyes

        Thanks.
          • 18397
          • 3,250 Posts
          I hate to have to be the one to say this but this feature was already coded in the next version...
            • 9849
            • 74 Posts
            I hate to have to be the one to say this…

            Why? It’s a good news, so you can be glad to be the one to say this. By the way, thanks for implementing the feature.
              • 6726
              • 7,075 Posts
              @ Florian : Pretty interresting, thanks for sharing !

              @ Heliotrope : Nice tip, I’ll have this added laugh

              Edit : Found the place to add the code, wasn’t line 89 but 45... typo or did I miss something ?

                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l&#39;outil id
                • 33337
                • 3,975 Posts
                Thanks for the nice snippet florian.

                I’ve added "code" tags to your first post.

                regards.

                zi
                  Zaigham R - MODX Professional | Skype | Email | Twitter

                  Digging the interwebs for #MODX gems and bringing it to you. modx.link