styling internal links

107 views
Skip to first unread message

UBi

unread,
Aug 5, 2015, 8:08:50 AM8/5/15
to TiddlyWiki
Hello,

In my TiddlyWiki I have tiddlers describing my pets: [[Cat Fred]], [[Dog Jimmy]], [[Mouse Beanie]], [[Squid Joe]] [[Dog Joe]], [[Spider Gonzo]].....
All of them are tagged with "Pet".

I would like those links to be displayed with neat icons instead of  the animal prefixes, e.g.
[[Dog Joe]] should be rendered as <a href="#Dog%20Joe"><img src="Dog.png"><span>Joe</span></a>, as opposed to
[[Squid Joe]] --> <a href="#Squid%20Joe"><img src="Squid.png"><span>Joe</span></a>.

Is there a way to achieve this with CSS/Macros/Widgets, without writing a JavaScript plugin?

TIA
Uwe

Eric Shulman

unread,
Aug 5, 2015, 8:25:01 AM8/5/15
to TiddlyWiki
\define PetLink(what,who)
<a href="#$what$%20$who$"><img src="$what$.png"><span>$who$</span></a>
\end

<<PetLink Dog Joe>>
<<PetLink Squid Joe>>

enjoy,
-e
Eric Shulman
ELS Design Studios
TiddlyTools - "Small Tools for Big Ideas!"
InsideTiddlyWiki: The Missing Manuals

YOUR DONATIONS ARE VERY IMPORTANT!
HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:

UBi

unread,
Aug 5, 2015, 9:17:02 AM8/5/15
to TiddlyWiki
Thanks, Eric,

it's working like expected, when I'm writing the links manually.

But how would I use the macro whithin a list?

<$list filter="tag[Pet]"><<PetLink <<currentTiddler>>>></$list>

obviously won't work.

Thanks again
Uwe

Jed Carty

unread,
Aug 5, 2015, 12:08:30 PM8/5/15
to TiddlyWiki
The prefix and removeprefix filter operators should help.

I am a bit busy right now, if you need I can put together how to do it later.

c pa

unread,
Aug 5, 2015, 3:22:24 PM8/5/15
to tiddl...@googlegroups.com
Not sure why this doesn't work but it should (Instead this displays the html rather than rendering it)

\define getFirstWord(sentence)
    <$list filter="$sentence$ +[first[]]"><$view field="title"/></$list>
\end
\define getLastWord(sentence)
    <$list filter="$sentence$ +[last[]]"><$view field="title"/></$list>
\end
\define intermediate(what,who)
   <$macrocall $name="PetLink" what="$what$" who="$who$" />
\end
\define makePetLink(tiddlerName)
    <$macrocall $name="PetLink"
            what=<<getFirstWord "$tiddlerName$">>
            who=<<getLastWord "$tiddlerName$">>
    />
\end
\define PetLink(what,who)
    <$link to="$what$ $who$"><img src="$what$.png"><span>$who$</span></$link>
\end

<$macrocall $name="PetLink"
        what=<<getFirstWord "dog sparky">>
        who=<<getLastWord "dog sparky">>
/>

<$macrocall $name="makePetLink"
        tiddlerName=<<currentTiddler>>
/>

<$macrocall $name="makePetLink"
        tiddlerName="dog sparky"
/>

<<makePetLink "dog sparky">>

UBi

unread,
Aug 6, 2015, 5:00:23 AM8/6/15
to TiddlyWiki
Due to the given examples, I think I got the figure. Thanks to all!

Meanwhile, I decided to use CSS to assign icons to the links. So my given example would change to

\define getfirst(tid) <$list filter="$tid$ +[first[]]"><$view field="title"/></$list>
\define getrest(tid) <$list filter="$tid$ +[rest[]]"><$view field="title"/></$list>
\define PetLink(first,rest) <$link to="$first$ $rest$" class="$first$">$rest$</$link>
\define makePetLink(tid)
 <$macrocall $name="PetLink" first=<<getfirst "$tid$">> rest=<<getrest "$tid$">> /
>
\end

Start sample output
<<getfirst "Dog Zerberus">>
<<getrest "Dog Zerberus">>
<<PetLink "Dog" "Zerberus">>
<<makePetLink "Dog Zerberus">>
End sample output

all in one tiddler. The result:

Start sample Output

Dog

Zerberus

Zerberus

<$link to="Dog Zerberus" class="Dog">Zerberus</$link>

End sample output


So the final question is the same as c pa's: How can I turn the last line in a working link?

Thanks
Uwe

UBi

unread,
Aug 7, 2015, 7:36:37 AM8/7/15
to TiddlyWiki
Hi,

now this is working for me:

\define rmprefix(tid,pref)
 
<$list filter="[[$tid$]] +[removeprefix[$pref$ ]]" emptyMessage="$tid$">
   
<$view field="title"/>
 
</$list>
\end
\define petLink(tid)
  <$set name="prefix" filter="$tid$ +[first[]]">
    <$link to="$tid$" class=<<prefix>>>
      <$macrocall $name="rmprefix" tid="$tid$" pref=<<prefix>>/
>
   
</$link>
  </
$set>
\end

<<petLink "Cat Mitzi">>
<<petLink "Dog Zerberus">>

Thanks,
Uwe
Reply all
Reply to author
Forward
0 new messages