First of all, thanks for this snippet, safed me some serious hairpulling =)...
It works up to 90%, I just have a problem together with Ditto and I couldn’t solve it myself, this is the reason I’m warming up such an old thread.
What am I trying to do?: I think it’s simple but anyways...I try to aggregate articles on the front page. You can see my modx directory/container-structure here:
http://picasaweb.google.ch/lh/photo/A1X3bqd7Kq34SE_Bag-czQ?feat=directlink
I have containers for the nav called "Home", "Musik" and so on, then I made subcontainers for the articles which have one page for each article. I then make a Ditto-Call
[!Ditto? &parents=`65` &tpl=`cfm_content_dto.articleTpl` &orderBy=`menuindex ASC`!]
in the content area of "Home" with a special template. This works fine, all the articles are displayed.
The problem I had now are some template variables...they are optional, means there can be content (link or image) in it or there can be no content. In case no content is inserted the TV should not be displayed. (see
http://picasaweb.google.ch/lh/photo/tsCWGaWnL8_SqxE1ybNlsQ?feat=directlink)
here my Ditto-Template (cfm_content_dto.articleTpl) before my try. This displays the articles right with links, images and everything...but if there is no link for the title or no image, placeholders are put in or in case of the title the url of the page is simply inserted instead of <span>[+title+]<span> (without the <a href></a>)...In consequence a header that isn’t ment as a link becomes a link and I wanted to change that, so it stays unlinked:
<div class="article">
<h1 class="article-header png">
<span><a href="[+cfm_article_link+]">[+title+]</a></span>
<small>» [+longtitle+]</small>
</h1>
<a href="[+cfm_article_thumb_link+]"><img src="[+cfm_article_thumb_src+]" alt="Artikel Thumbnail" class="content-thumb" /></a>
[+introtext+]
<div class="mehr">
<a href="[+cfm_article_img_link+]"><img src="[+cfm_article_img_src+]" alt="Bierhübeli Logo" class="content-img" /></a>
[+content+]
</div>
<input type="button" name="mehr" class="mehr-button no-script" value="mehr..." />
</div>
So I found this snippet and the extended version from dev_cw
$tv = isset( $tv ) ? $tv : "";
// get tv name
$cnd = isset( $cnd )? $cnd: "";
// get conditional
$rtn = isset( $rtn )? $modx -> getChunk( $rtn ): "";
// get chunk to return
$rtn2 = isset( $rtn2 )? $modx -> getChunk( $rtn2 ): "";
// get chunk to return
$id = isset( $id )? $id: $modx -> documentObject['id'];
// get current page ID
$tvarray = $modx -> getTemplateVarOutput( $tv, $id, $published = 1 );
$cnd = explode( ',', $cnd );
$value = $cnd[0];
$filtertype = isset( $cnd[1] ) ? $cnd[1] : 2;
if ( $filtertype == 1 && ( !isset ( $tvarray[$tv] ) || $tvarray[$tv] != $value ) ) {
return $rtn;
} else if ( $filtertype == 1 && ( !isset ( $tvarray[$tv] ) || $tvarray[$tv] == $value ) ) {
return $rtn2;
} else if ( $filtertype == 2 && $tvarray[$tv] == $value ) {
return $rtn;
} else if ( $filtertype == 2 && $tvarray[$tv] != $value ) {
return $rtn2;
}
so I made two chunks, one if there is a link in the TV and one if there’s none.
cfm_art.header.linked
<span><a href="[*cfm_article_link*]">[*pagetitle*]</a></span>
cfm_art.header.unlinked
<span>[*pagetitle*]</span>
then I changed the Ditto-Template to (Notice the Snippet call):
<div class="article">
<h1 class="article-header png">
[[TVifelse? &tv=`cfm_article_link` &cnd=`, 1` &rtn=`cfm_art.header.linked` &rtn2=`cfm_art.header.unlinked`]]
<small>» [+longtitle+]</small>
</h1>
<a href="[+cfm_article_thumb_link+]"><img src="[+cfm_article_thumb_src+]" alt="Artikel Thumbnail" class="content-thumb" /></a>
[+introtext+]
<div class="mehr">
<a href="[+cfm_article_img_link+]"><img src="[+cfm_article_img_src+]" alt="Bierhübeli Logo" class="content-img" /></a>
[+content+]
</div>
<input type="button" name="mehr" class="mehr-button no-script" value="mehr..." />
</div>
this does give me "Home" as title for every Article and that’s the pagetitle of the container-page and not the title of the article-page.
For the article-pages I have made a specific template (to display every article on its own page if necessary):
<div class="article">
<h1 class="article-header png">
[!TVifelse? &tv=`cfm_article_link` &cnd=`, 1` &rtn=`cfm_art.header.linked` &rtn2=`cfm_art.header.unlinked`!]
<small>» [*longtitle*]</small>
</h1>
<a href="[*cfm_article_thumb_link*]"><img src="[*cfm_article_thumb_src*]" alt="Artikel Thumbnail" class="content-thumb" /></a>
[*introtext*]
<div class="mehr">
<a href="[*cfm_article_img_link*]"><img src="[*cfm_article_img_src*]" alt="Artikel Image" class="content-img" /></a>
[*content*]
</div>
<input type="button" name="mehr" class="mehr-button no-script" value="mehr..." />
</div>
I made the same Snippet call (ok, I let it uncached here because it’s not called in a snipptets template like above) and here it works. So when I view the single article pages the titles are linked or not depending if there is something in the cfm_article_link TV...
this says to me that there must be a problem with the document ID from which the title is taken, could it be from the TVifelse Snippet
$id = isset( $id )? $id: $modx -> documentObject['id'];
// get current page ID
or is it a Ditto problem because TVs in Ditto are called with [+tvname+] instead of the normal [*tvname*]??
I already tried:
cfm_art.header.linked
<span><a href="[+cfm_article_link+]">[+pagetitle+]</a></span>
cfm_art.header.unlinked
<span>[+pagetitle+]</span>
but this didn’t even output a wrong title (like "Home") it did nothing at all...
I really don’t know further and would appreciate every help! Thx in advance.