conditional display / template parameter

721 views
Skip to first unread message

Erwan

unread,
Oct 25, 2015, 6:51:22 AM10/25/15
to TiddlyWiki

Hi everyone,

I have a template MyTemplate which contains several complex parts, for
instance:

Part1
Part2
Part3
Part4

I would like Part2 and Part4 to show up only depending on some condition:

Part1
if (condition) Part2
Part3
if (condition) Part4

so that the tiddler from which the template is called can select which
version to display, for example by setting a variable:

<$set name="showAll" value="no">
{{||MyTemplate}}
</$set>

Remark: it doesn't have to be with a variable, I'm fine using any other
mechanism which has the intended effect.

What is the best way to achieve something like that please?

Regards,
Erwan

Jed Carty

unread,
Oct 25, 2015, 7:34:53 AM10/25/15
to TiddlyWiki
A reveal widget would be the simplest way, just have something like this in your template:

part1
part2
<$reveal type='match' state='!!show_3' text='yes'>
part3
</$reveal>
<$reveal type='match' state='!!show_4' text='yes'>
part4
</$reveal>

then if a tiddler has a field called show_3 with the text 'yes' than part3 will be shown, and the same with show_4 and part4.

Another way is to use a list widget like this:

part1
part2
<$list filter='[is[current]show_3[yes]]'>
part3
</$list>
<$list filter='[is[current]show_4[yes]]'>
part4
</$list>

which would check the same conditions as the first one.

There seem to be some situations where the list is better and some where reveal is better but I am not sure what causes it.

Eric Shulman

unread,
Oct 25, 2015, 8:03:26 AM10/25/15
to TiddlyWiki
On Sunday, October 25, 2015 at 3:51:22 AM UTC-7, Erwan wrote:
...so that the tiddler from which the template is called can select which
version to display, for example by setting a variable:

<$set name="showAll" value="no">
   {{||MyTemplate}}
</$set>

You can use a variable to control which $reveal widgets are shown in MyTemplate, like this:

<$reveal text=<<showAll>> type="nomatch" default="no">
   ...conditional content here...
</$reveal>

The above wiki syntax is equivalent to:

if (showAll != "no") {
   ... content ...
}

enjoy,
-e

Erwan

unread,
Oct 25, 2015, 9:33:55 AM10/25/15
to tiddl...@googlegroups.com

Thank you both for your suggestions!

In this case I was confusingly looking for matching the reveal widget against a variable, Eric's solution works perfectly.
Erwan
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/02a634f8-29e7-404b-b056-0b9edd828cb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mat

unread,
Oct 25, 2015, 9:34:27 AM10/25/15
to TiddlyWiki
[I feel like a kid locked into a car driving by Disneyland. I'm really busy with other stuff but popped by just to take a peek... hope to engage again more soon...]

I am, for a semi-public site, using a list filter with some conditional parameters for an IF statement. If true, i.e if anything comes out of the filter, then styles are set to show/hide stuff (primarily properties "visibility" and "display" - note/check up the difference between "visibility:hidden" and "display:none"). I.e I put <style></style> inside the list filter and this is only activated if the filter does fulfill some test.

Tell me if you want to see the actual example.

<:-)

Erwan

unread,
Oct 25, 2015, 9:49:17 AM10/25/15
to tiddl...@googlegroups.com

Thank you Mat, interesting method.

About that, I realized only recently that you can use a text reference inside a style definition, e.g.:

<style>
.my-style {
font-size: {{Config!!font-size}};
}
</style>

I guess that could be used as well using the css properties that you mention in order to show/hide something.
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.

Mat

unread,
Oct 25, 2015, 9:56:16 AM10/25/15
to TiddlyWiki
About that, I realized only recently that you can use a text reference inside a style definition, e.g.:

In deed - actually, you can find many instances of this in default TW and the stylesheets. Valuable technique!!!

<:-)
Reply all
Reply to author
Forward
0 new messages