[5] Why some places <<variable>> is evaluated and others it's just a string

112 views
Skip to first unread message

Mike Wright

unread,
Jan 7, 2017, 4:06:30 PM1/7/17
to TiddlyWiki
Hi everybody. Entry level user here and already stumped!

I'm trying to use the value of a $set, which is the name of a tiddler, inside a link ( [[...]] ).


<$set name='VIDEO' value='My Favorite Movie'>
  Watch [[<
<VIDEO>>]]
  Watch <a href='<
<VIDEO>>'><<VIDEO>></a>
</$set>


The value inside the [[]] and the href attribute is the string literal "<<VIDEO>>" but the value inside the <a/> is "My Favorite Movie".

Can somebody explain what I'm missing, what is the difference between the two, and how to get the VALUE of <<VIDEO>> into the links, or am I even using the right approach?

Thanks from a tw5 noob,
Mike Wright

Tobias Beer

unread,
Jan 7, 2017, 4:51:08 PM1/7/17
to TiddlyWiki
Hi Mike,

The main question is: What precisely are you trying to achieve?

It's quite odd to see that url be filled with the title. Video being defined as "My Favorite Movie", it's definitely not a URL for anything.

So, here's some stuff for you to play with, understand, and read about on tiddlywiki.com:

<$vars title="My Favorite Movie" link="[[$(title)$]]">
<$set name="url" filter="[
<title>get[url]]">

  Watch <$link to=<
<title>>><$text text=<<title>>/></$link>

  Watch <
<link>>

  Watch <a href=<
<url>> target="_blank"><$text text=<<title>>/></a>
</$set>
</$vars>

Read:
  • VarsWidget => a shorthand for set
  • TextWidget => Why? Because that title may get wikified, e.g. contain CamelCase or stuff that triggers other wiki parser rules to kick in
  • LinkWidget => to generically link
  • Filters => you definitely need those
Best wishes,

Tobias.

Mike Wright

unread,
Jan 7, 2017, 5:49:57 PM1/7/17
to TiddlyWiki


On Saturday, January 7, 2017 at 1:51:08 PM UTC-8, Tobias Beer wrote:
Hi Mike,

The main question is: What precisely are you trying to achieve? 
 
I have a tiddler with tabs, each tab caption is the name of a video that is also the name of a matching tiddler that has the <embed> markup to YouTube.  I need to be able to use a link in the embedded tiddler to get to that same tiddler, only stand alone, i.e. separate from the twiddler with all the tabs, because it has additional controls such as Watched (uncheck to unWatch, etc.).
  
It's quite odd to see that url be filled with the title. Video being defined as "My Favorite Movie", it's definitely not a URL for anything.

It's not. It's the name of a twiddler.  When clicked I want that twiddler to be opened.  You provided the solution with the <$link/> widget.  I'd tried using that but had the syntax wrong.  Now I can see the similarity to the html <a> markup with the <$link> widget enclosing the <$text> widget.

Watched <$link to=<<title>>><$text text=<<title>>/></$link>
Watched <a    href="title" >         title         </a>

Next stop is to create a form twiddler that will collect the video info and generate an appropriately tagged tiddler for it so it will automatically appear in the "tabs" page, which will finish my video library/player app.

This TW is awesome stuff.

Thanks for the help and pointers.
 

Tobias Beer

unread,
Jan 8, 2017, 8:25:32 AM1/8/17
to tiddl...@googlegroups.com
Hi Mike,
 
I have a tiddler with tabs, each tab caption is the name of a video that is also the name of a matching tiddler that has the <embed> markup to YouTube.  I need to be able to use a link in the embedded tiddler to get to that same tiddler, only stand alone, i.e. separate from the twiddler with all the tabs, because it has additional controls such as Watched (uncheck to unWatch, etc.)

Sounds interesting to have the caption actually point to another tiddler. On the other hand, what's the title of that Movie tiddler then, if not its caption? What do you display as the tab title? Would be great if you could post some results in the end.so we can have a look at how that unfolds.

 It's quite odd to see that url be filled with the title. Video being defined as "My Favorite Movie", it's definitely not a URL for anything.

It's not. It's the name of a tiddler.

Ah, ok. Now I understand what you were after. Generally speaking, you can actually use the generic html a element, but it's not as convenient s the shorthand wiki syntax or the link widget version. In general, you can address tiddlers via anchors like so:

<$vars anchor="#$(title)$" title="Customise TiddlyWiki">
<a href=<
<anchor>> class="tc-tiddlylink"><$text text=<<title>>/></a>
</$vars>

In the above, the link to the tiddler is created as an anchor, basically concatenating the # sign with the title stored in a $(variable)$ for substitution when rendered, I've given it the class tc-tiddlylink to have it look like an internal link. Not that I would know if and when that is useful, but just so you know that it does, in fact, work that way, too.
 
Next stop is to create a form tiddler that will collect the video info and generate an appropriately tagged tiddler for it so it will automatically appear in the "tabs" page, which will finish my video library/player app

Will be interesting to see, if and how you'll be implementing some sort of categorization.

For example, you could very well have "movie category tiddlers" that will automagically show a list of movie tabs at the bottom when you open them using some:

Conditional ViewTemplate Section @ tb5

e.g. "Drama" is a tiddler tagged "Movies" and "Garden State" and "Lost in Translation" are tiddlers tagged "Drama", then you could define a conditional ViewTemplate like so which should render tabs for the last two for the tiddler "Drama":

title: $:/_my/movies/tabs
tags
: $:/tags/ViewTemplate
list
-after: $:/core/ui/ViewTemplate/body

<$list filter="[all[current]tag[Movies]]">
<$vars state="$:/states/tabs/movies/$(currentTiddler)$">
<$set name="first" filter="[all[current]tagging[]limit[1]]">
<$set name="first" filter="[<title>get[caption]]" emptyValue=<<title>>>
<$macrocall $name=tabs tabsList="[all[current]tagging[]]" default=<<first>> state=<<state>>/>
</
$set>
</$set>
</
$vars>
</$list>

Now, there's plenty going on here, but after a bit of deciphering it's quite clear what's going on and how that works:
  1. we define some system tiddler tagged $:/tags/ViewTemplate to be shown after the general body / content of the tiddler:
  2. it's contents will only show anything, if the current tiddler is tagged Movies, hence a movie category
    • the $list widget can be quite handy to conditionally display stuff
      • but if you do, mind that it sets the currentTiddler, so use the "variable" attribute should you not want <<currentTiddler>> to change
      • in this case, we're fine though, since we operate under the current tiddler using [all[current]]
  3. we define a state to be used for the tabs we render later based on the name of the movie category
    • using this state, TiddlyWiki remembers the "open tab"
    • the title of the state tiddler is any title you want, but I generally put it under "$:/states/whatever"
    • I never save those (when saving the wiki) because they are not save-worthy to me
      • MS Word also doen't remember if in the last session you had the file menu open, and so it opens that again, highlighting the last item you were hovering with your mouse
  4. we figure out a way to identify the first item to be shown in the tabs,
    • because nothing is more awful than the a first tab not being displayed by default when the tabs are rendered
    • so there's a set widget using a filter to determine the first tab tiddler, the first movie tiddler tagged with that movie category
    • another set widget again uses a filter to fetch any caption for that tiddler, defaulting to the title... which is what TiddlyWiki stores in that tabs state
    • I actually just created an issue to address this oddity:

      #2701 allow user to define default for tabs as first title 
      https://github.com/Jermolene/TiddlyWiki5/issues/2701

  5. eventually we render the tabs
    • you probably will / want to use a custom template for showing your movie details
Best wishes,

Tobias.

Jeremy Ruston

unread,
Jan 8, 2017, 1:18:55 PM1/8/17
to tiddl...@googlegroups.com
Hi Mike

On 7 Jan 2017, at 21:06, Mike Wright <mike...@gmail.com> wrote:

The value inside the [[]] and the href attribute is the string literal "<<VIDEO>>" but the value inside the <a/> is "My Favorite Movie”.

Just to acknowledge that this inconsistency frustratingly crept in very early in TW5’s development, and then proved hard to fix without breaking backwards compatibility.

Best wishes

Jeremy
Reply all
Reply to author
Forward
0 new messages