On 03/01/16 00:45, Eric Shulman wrote:
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



Hi Eric,

Thank you for your answer. I see now why this is tricky... Unfortunately I have two problems with your solution:

- As far as I understand, I still need to define my tiddler custom classes in a stylesheet tiddler, where I cannot use the tiddler-specific color, is that correct?

- when I tested this solution I found that modifying $:/core/ui/ViewTemplate apparently caused a bug in the navigation: when clicking on a link from the "open" or "recent" tab, the browser doesn't take me to the tiddler as it should. I tested with Firefox and Chrome on a TW version 5.1.8 (does that matter?).

Do you see something to do about that? if it's too complicated it's ok, I can probably live without my custom colored borders! ;-)

Cheers,
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 [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/56895A9D.2030906%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to