On Saturday, January 2, 2016 at 3:15:20 PM UTC-8, Erwan wrote:
>
> I would like to apply some specific style rules to tiddlers which 
> satisfy a given condition (e.g. [has[my-field]]), and (to make things 
> harder) I would like to be able to use the "color" field of the current 
> tiddler. For example, with the following CSS rules every tiddler should 
> have a thick border colored according to its "color" field: 
>
> <style> 
> .tc-tiddler-frame { 
>    border-style: solid none none solid; 
>    border-width: 5px; 
>    border-color: {{!!color}}; 
> } 
> </style> 
>
> Is this possible? 
>

When the CSS content is evaluated, it isn't in the context of a specific 
tiddler, but rather, in the context of the stylesheet tiddler, so the 
reference to {{!!color}} would only pick up the color value from a field on 
the stylesheet tiddler itself (i.e., {{currentTiddler!!color}}.  In 
addition, the CSS rule for .tc-tiddler-frame is applied to all tiddlers, 
not just the current one.  That is why Jeremy automatically generates the 
".tc-tagged-SomeTag" class attributes for tiddlers.  It provides a way to 
differentiate between tiddlers so that CSS rules can be selectively applied 
simply by adding a tag.

Without using tagging, the problem is a bit more complicated.  You need to 
modify the core's ViewTemplate definition so that you can add your 
tiddler-specific custom classes to the tiddler frame directly.  Something 
like this:
\define frame-classes()
tc-tiddler-frame tc-tiddler-view-frame $(missingTiddlerClass)$ $(
shadowTiddlerClass)$ $(systemTiddlerClass)$ $(tiddlerTagClasses)$ $(
tiddlerCustomClass)$
\end
<$set name="storyTiddler" value=<<currentTiddler>>><$set name=
"tiddlerInfoState" value=<<qualify "$:/state/popup/tiddler-info">>><$tiddler 
tiddler=<<currentTiddler>>>
<$set name="tiddlerCustomClass" value={{!!class}}><!--ADDED-->
<div class=<<frame-classes>>><$list filter=
"[all[shadows+tiddlers]tag[$:/tags/ViewTemplate]!has[draft.of]]" variable=
"listItem"><$transclude tiddler=<<listItem>>/></$list>
</div>
</$set><!--ADDED-->
</$tiddler></$set></$set>


1) added <$set name="tiddlerCustomClass" ...> to fetch the value of the 
"class" field from the current tiddler
2) added $(tiddlerCustomClass)$ to frameclasses macro definition

With this in place, you can then apply custom CSS classes on a per tiddler 
basis simply by adding a "class" field to that tiddler.

enjoy,
-e

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/9c1cc2d2-d16f-4be1-bb93-12161b1d48b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to