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"
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;