@twMat it is true that one gets mixed messages about the use of the $wikify widget, this is because it ties back to the whole structure and operation of tiddlywiki. To understand it, is largely conceptual. I will try and explain how I understand it and perhaps it will resonate with you. But first lets discuss the best work around.
Avoiding Wikify
The reason people often wish to use Wikify is to “evaluate” something within tiddlywiki and use this to alter the logic and output of their TiddlyWiki script. We have now being given the /function and the backtick “Substituted Attribute Values” which will be evaluated in line without needing to wikify.
- Filters (within functions) give you access to tiddler, fields and variables allowing you to interogate almost anything.
- Substituted attribute values can do the same, including references, using variables/filters and functions.
Filters have so many features, that arguably there is very little you can’t evaluate and there is no need to wikify.
- If we find examples where we must use wikify, there is an argument we found a gap we need to address in the core.
What is wikify?
It is importiant to understand that the wikify widget makes possible something that is always happening in tiddlywiki and normaly at the very last moment.
- Rendering - making the output into html to be presented in the browser
- It is also importiant to realise the TiddlyWiki Script is not a procedural language.
- Perhaps it is a declarative language?
Tiddlywiki takes text, wikitext and TiddlyWiki script and “eveluates it”, then converts it to html, and thus displays it.
- Sure the widget allows more than this, but that is basicaly what its doing, although it has other utility functions
- You can see from this, that wikification is the last thing before displaying things, so perhaps you can see how this is kind of problamatic, using wikify, you are doing this before hand, to alter the flow of your code.
- Tiddlywiki needs to guarentee it renders and returns control to the user and ASAP.
I have struggled with this myself, but have come to realise some concepts that help me here. They are backed up by facts but serve as guidence.
Widgets are places things go to be displayed
Unlike macros and wikitext, a widget is usualy a place where things go to be displayed, or interacted with, think of the $view and $edit widgets.
- This occurs even if the result is something we can interact with such as a $button or a $select, tiddlywiki renders it and stops and then lets the user interact with it.
This is effectivly true for all widgets, except actionwidgets which have a special role, once triggered.
- They independantly modify one or more tiddlers/fields in the wiki.
The very common widget we use is the $list widget, which seems to break this rule because we nest things inside it, but this is still true, no matter how deep you nest, each widget nesting does not communicate with what included it, they go and do what they do and must complete, before the rendering is finished, then tiddlywiki renders thet next part of your tiddler.
- Lucky for us the result of widgets is mostly placed on the screen so we can see its output and only when the rendering finishes, can we again interact with it (think of what happens with infinite loops).
- TiddlyWikis design makes it look like one change is imediatly reflected throughout the whole wiki, which is its beauty, but to do this it needs to be very performant and guarentee it finishes. This drives what a widget is.
- Changing only what it must, is achived using a tree like structure, only propergate changes out along the branches that the change affects.
Yes, these Create variables include $vars and even $list (on currentTiddler), variables that are only valid within them. ie once they are closed </$let>
or at the end of the tiddler.
- These can be set with literals, references (fields/tiddlers) But ALSO evaluated “functions” and “Substituted Attribute Values”.
In closing
If you take the above into account, that widgets are nested within widgets and resolved to produce output and that it needs to be fully resolved, before moving onto the next part of wikitext (Branches of the tree from here). You may see that, $wikify trys to do the whole rendering for a nominated part then use its output in your script, before it then has to render the whole wiki (or parts that changed) to display on screen, that wikify is in some ways playing with the underlying system. It renders its contents (early) then sets a variable to the result, to be used before it renders the whole wiki.
- The fact we do not need to be aware of the above is a tribute to tiddlywiki, but sometimes we just need to know.
- You can perhaps see that as a result, it is best avoided, as not being in the spirit of the way tiddlywiki works. Taking something from the end and using it in the middle.
note
I may edit the above for meaning in responce to others comments or review.