Question: How to eliminate <$wikify?

Hi all,

I hear that wikify should be omitted – something I find difficult in cases like this. Maybe some wiser TWizard can see a solution here?

The new version of my macro that jumps up and down the story (next/previous tiddler) looks like this at the moment:

\define TiddlerExpress(step:"0")
<$let nth={{{ [list[$:/StoryList]allbefore:include<currentTiddler>count[]add[$step$]] }}} target={{{ [list[$:/StoryList]nth<nth>] }}}>
<$wikify name="focus" text="section.lox-tiddler:nth-child(<<nth>>n+1) button">
<$wikify name="refocus" text="section.lox-tiddler:nth-child(<<nth>>n+1) a">
<$action-sendmessage $message="tm-focus-selector" $param=<<focus>> preventScroll="true"/>
<$action-sendmessage $message="tm-focus-selector" $param=<<refocus>> preventScroll="true"/>
<$action-navigate $to=<<target>>/>
</$wikify>
</$wikify>
</$let>
\end

Is there a way to omit the wikify parts?

Thank you and all the best,
Thomas

Something along these lines would work:

\define TiddlerExpress(step:"0")
<$let
	nth={{{ [list[$:/StoryList]allbefore:include<currentTiddler>count[]add[$step$]] }}}
	target={{{ [list[$:/StoryList]nth<nth>] }}}
	focus={{{ section.lox-tiddler:nth-child( [<nth>] n+1) button :and[join[]] }}}
	refocus={{{ section.lox-tiddler:nth-child( [<nth>] n+1) a :and[join[]] }}}
>
<$action-sendmessage $message="tm-focus-selector" $param=<<focus>> preventScroll="true"/>
<$action-sendmessage $message="tm-focus-selector" $param=<<refocus>> preventScroll="true"/>
<$action-navigate $to=<<target>>/>
</$let>
\end

Text substitution is unfortunately still quite clumsy in filters. Personally I use a custom filter that allows syntax like:
focus={{{ [[section.lox-tiddler:nth-child($(nth)$n+1) button]printf[]] }}}
or
focus={{{ [[section.lox-tiddler:nth-child($0$n+1) button]printf<nth>] }}}

You can also use a macro like the .printf example that I provided in this thread to do text substitution for you.

Lastly, wikify should be avoided for performance reasons. However, using wikify within a macro that will be assigned as the actions of a triggering widget like $button is probably one of the areas in which the performance impact will be least felt. The actions are only parsed when they are invoked and thus refresh performance is less of a concern.

1 Like

Though… why not just use the data-tiddler-title attribute in the selector and not worry about nth child?

I had thought about this too and then worried about special characters in titles (") that might break my macro.

Thank you, @saqimtiaz, your code works as expected.

Good to know!

Cheers, -t

1 Like

For future reference, you can use triple double quotes """ for widget attributes and for the selector you can use the escapecss[] operator to make sure you have a valid selector.

3 Likes

Sorry to reopen this old thread, but it seems most appropriate to use this instead of a new one: Does “$let” wikify the variable?

Substituted Attribute Values can handle variable substitution.

IMO you should specify you usecase in a new thread a bit closer. In the new thread you can reference this one.

I have to tidy up before. I am building a filter for a grid that is formatted by tiddlerfields.
Therefore I have multiple values I need to concatenate by wikification which results in a very messy code. Replacing 4 wikify by 2 let expressions would be nice.

Returning to the Lead Topic and to help @JanJo

Question: How to eliminate <$wikify?

This is now achievable for anything that can be expressed as a filter, because a function returns the result after evaluating the filter, and as text (First value only).

  • Within this you can use parameters as variables [<varnam>] or the substitute operator.

And also for any substitution we can use the new parameters and backticks.

However if we return to the original question wikify is used to generate a string including a value of a variable;

<$wikify name="focus" text="section.lox-tiddler:nth-child(<<nth>>n+1) button">
<$wikify name="refocus" text="section.lox-tiddler:nth-child(<<nth>>n+1) a">

Then these are used as parameters as follows

<$action-sendmessage $message="tm-focus-selector" $param=<<focus>> preventScroll="true"/>
<$action-sendmessage $message="tm-focus-selector" $param=<<refocus>> preventScroll="true"/>

So instead of using the above we can now use the backticks as follows;

<$action-sendmessage $message="tm-focus-selector" $param=`section.lox-tiddler:nth-child($(nth)$n+1) button` preventScroll="true"/>
<$action-sendmessage $message="tm-focus-selector" $param=`section.lox-tiddler:nth-child($(nth)$n+1) a` preventScroll="true"/>
  • Above untested but I am confident.
  • Note we do not need the intermediate variables focus and refocus.

FYI: @telmiger followup for you.

2 Likes