[TW5]Can I use a field's value as a color code in template?

102 views
Skip to first unread message

Terry Chen

unread,
Nov 21, 2018, 4:40:49 AM11/21/18
to tiddl...@googlegroups.com
I created a tiddler "list" like this:

<$list filter='[tag[role]]' template='role_color_template'></$list>


and another tiddler named "role_color_template" like this:

<$view field='colorcode'/><br/>

this is the correct way to create a template, right?

Then I created a tiddler name "customer" with tag "role". I gave a field name="colorcode", value="#FF0000" to it.

So, in the "list" tiddler, it shows:
#FF0000

But, when I tried to put the code in "font" tag, just like this:

<font color="<$view field='colorcode'/>">The quick fox...</font><br/>


it doesn't work.

Is that possible?

Mark S.

unread,
Nov 21, 2018, 10:49:02 AM11/21/18
to TiddlyWiki
You can't use a widget as the input to an attribute. Widgets are like HTML tags. Just as you can't have an HTML tag inside (used as an attribute) another HTML tag, you can't use a widget inside an HTML tag.

But you can use transclusion, due to the miracle of wikitext rendering. So if you change your template to:

<font color={{!!colorcode}}>The quick fox...</font><br/>

This will work.

Good luck
-- Mark

BurningTreeC

unread,
Nov 21, 2018, 11:17:51 AM11/21/18
to TiddlyWiki
@Terry Chen, you can do this, also using the <$view..> widget, but Mark's solution is easier.

Using the <$wikify> widget:

<$wikify name="colorcode" text="<$view field='colorcode'/><br/>">
<font color=<
<colorcode>>>The quick fox...</font><br/>
</$wikify>


Terry Chen

unread,
Nov 21, 2018, 8:45:04 PM11/21/18
to TiddlyWiki
Thanks a lot!

Terry Chen

unread,
Nov 21, 2018, 8:47:13 PM11/21/18
to TiddlyWiki
Wow, this works too! thank you!

在 2018年11月22日星期四 UTC+8上午12:17:51,BurningTreeC写道:

Terry Chen

unread,
Nov 22, 2018, 2:11:46 AM11/22/18
to TiddlyWiki
May I ask a further question?

when I use a "span" tag, it doesn't work again:

<span style=color:{{!!colorcode}}>abc</span><br/>

Can I use it this way?

在 2018年11月21日星期三 UTC+8下午11:49:02,Mark S.写道:

Mohammad

unread,
Nov 22, 2018, 3:40:45 AM11/22/18
to TiddlyWiki
Use the method by BurningTreeC!
It should work!

<$wikify name="colorcode" text="color:{{!!colorcode}}">
<span style=<<colorcode>>>abc</span><br/>
</$wikify>

-Mohammad

Terry Chen

unread,
Nov 22, 2018, 8:22:38 AM11/22/18
to TiddlyWiki
ahhhhh! I know now...

It's amazing...

在 2018年11月22日星期四 UTC+8下午4:40:45,Mohammad写道:
Reply all
Reply to author
Forward
0 new messages