On Tuesday, June 29, 2021 at 1:15:35 AM UTC+2 jn.pierr...@gmail.com wrote:

Here are some things that *change the current tiddler*:
>
>    - Transcluding another tiddler with the {{curly braces}} syntax.
>    - Using a $list widget to enumerate the outputs of a filter.
>    - Directly setting currentTiddler with a $set or $vars widget.
>
> Does it mean that you can change the content of a var or that you stack up 
> vars, getting only the values from the top var?
>

You "stack up vars". So variables have a scope. That's the reason why we 
sometimse need a construction like this:

title: myTemplate

\define concat() $(currentTiddler)$-$(title)$

<$list filter="a b c" variable=title>
<<concat>>
</$list>

Since the list-widget would "overwrite" the currentTiddler with the default 
setting we can provide a new variable name. In this case "title"
The currentTiddler is the tiddler, the code lives in. 

If you create a new tiddler named: test ... You can play with templates. 

title: test

{{myTemplate}}

---

{{||myTemplate}}

 

> Could it be used to have some kind of recursion in a safe way?
>

Yes. We use recursion a lot. eg: the toc-macros. 
 

> I was thinking of vars as immutable stuff because of the syntax that 
> declare them but no syntax to alter them otherwise.
>

As I wrote. Variables have a scope. They are valid inside the widget they 
are defined in . 

\define test() abc
\define test() xyz

<<test>>  ... Will be xyz 

So the last one wins. The above code is a "*shortcut *of" 

<$set name=test value=abc>
<$set name=test value=xyz>

<<test>>

</$set>
</$set>

Try this: 

<$set name=test value=abc>

<<test>>

<$set name=test value=xyz>

<<test>>

</$set>
</$set>

 

> And finnally, in a number of my templates, the template content is only 
> <<myMacro>>. It seems a bit out of touch with what your telling me with 
> what template are. In effect, myMacro is only used there. Would it b a 
> better idea to ditch the macro and have the macro body directly into the 
> template text? (yes, myMacro has no params.)
>

It depends. When your code is finished, it is probably more efficient that 
the template only contains the template text. 
But for testing the following makes sense. 

title: xTemplate

\define  myMacro() 
this code works but looks odd
\end

\define myMacro()
this code is  WIP but might look better in the end. 
\end

<<myMacro>>

This gives you the possibility to easily test new code, without overwriting 
your "old but working" code. ... BUT BUT BUT ... 
Once the new code works and is cleaner. You need to remove the old code. .. 
There should be only 1 "source of truth"

Otherwise you will have a nightmare to maintain your code .. trust me ;)

-mario


-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/609a6264-8676-45a5-ac1d-5820fb1f33fcn%40googlegroups.com.

Reply via email to