Conditional view template Q

144 views
Skip to first unread message

David Gifford

unread,
Nov 26, 2016, 11:44:36 AM11/26/16
to TiddlyWiki
Hi all

I know how to create a conditional view template that includes a list widget or list-links macro. My question has to do with titles for the list. I would like a title before the list ("Related topics"). But I would only like the title to appear conditionally, if there are items in the list. So if, in this instance, there are no backlinks to this tiddler, the title "Related topics" will not show.

In TW classic terminology, "if backlinks, show list title and show list of links to tiddlers backlinking here." And if no backlinks, nothing appears in the tiddler.

Any way to do this?

Jed Carty

unread,
Nov 26, 2016, 5:36:25 PM11/26/16
to TiddlyWiki
You just put your test inside the conditional part of the template. Something like:

<$list filter='[is[current]tag[foo]]'>
<$list filter='[is[current]backlinks[]limit[1]]' variable=dummy>


!Look at me! I am a title!


<$list filter='[
<currentTiddler>backlinks[]]'>


</$list>


</$list>
</$list>

note that the variable=dummy is needed in the second list widget. It doesn't have to be dummy, but it has to be something. Also replace  [is[current]tag[foo]] with whatever filter you want for your conditional part.

David Gifford

unread,
Nov 26, 2016, 6:23:35 PM11/26/16
to TiddlyWiki
Hi Jed

Thank you, though I confess I am too ignorant to understand your example. I tried experimenting with it for a while but I am obviously doing something wrong.

Also, I forgot to mention that the title will not be on a separate line. Below is what I created originally to make it look like I want. It consists of two list filters that will all flow together on the same line. The alt arrows are the 'titles' I am talking about.

<$list filter="[all[current]tags[]sort[title]]"> ↑ <$link><span class="giffbuttonsgreen"><$view field="title"/></span></$link></$list> <$list filter="[all[current]backlinks[]sort[title]] -[all[current]tags[]] -[all[current]links[]]"> ↔ <$link><span class="giffbuttonsblue"><$view field="title"/></span></$link></$list>

CSS:

.giffbuttonsblue {padding:2px;background-color:#DDF;padding-left:8px;padding-right:8px;line-height:25px;margin-right:8px;font-size:10pt;}

.giffbuttonsgreen {padding:2px;margin-top:30px;background-color:#DFB;padding-left:8px;padding-right:8px;line-height:25px;margin-right:8px;font-size:10pt;}

html body.tc-body a.tc-tiddlylink .giffbuttonsgreen {color:#694;}

What do I need to tweak in your example? It looked like a filter in a filter in a filter, and it wasn't clear to me what each part does. Sorry for my ignorance!

Mark S.

unread,
Nov 26, 2016, 7:25:55 PM11/26/16
to TiddlyWiki
Hi Dave,

I think you need to explain what's not working for you. I stuck Jed's code into a template, added in your code and stylesheet, created a tiddler tagged "foo" and another tiddler that linked to it, and got the results as attached. Everything seems to be working.

In Jed's code, the first filter makes sure that the template is only being applied inside tiddlers tagged "foo". The second filter makes sure that there are backlinks to display. If there are no backlinks to the tiddler, nothing is displayed. The inner list (which I substituted with your code) displays the list of backlinks.

Good luck!
Mark
footest.png

David Gifford

unread,
Nov 26, 2016, 7:53:13 PM11/26/16
to tiddl...@googlegroups.com
Hey, I got it to work! Just changed "[is[current]tag[foo]]"  to "[is[current]]" and added the list filter on the inside one. I thought Jed was saying my list filter needed to go in place of tag[foo].

Thanks Jed and Mark!

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/NuE37lXQGfA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+unsubscribe@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/865e30e9-9d18-41cf-a965-c49750b9da58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
David Gifford
Christian Reformed World Missions, Mexico City

Reply all
Reply to author
Forward
0 new messages