Dynamically change caption field (or just title in tabs macro) in TiddlyWiki - tiddlywiki

I'm putting together some TiddlyWiki templates, and I've run into something that would be nice to have, but I'm not sure whether it's actually possible.
I have some tiddlers that I'm including in another tiddler using the tabs macro. Each tiddler has one of two tags associated with it. I'd like to append a snippet of text to the caption in the tab view, based on which tag is associated.
I don't have a strong preference for whether this is done by adding some kind of callback to edit the caption on save, something that somehow calculates the desired caption on the fly, altering the invocation of the tabs macro to recalculate the caption on render, or somehow causing the templates to calculate the caption field.
I haven't found anything promising going through the documentation, but maybe I just haven't figured out what's relevant to my issue. I find that happens a lot.
Like, I'm sure I can write conditionals based on whether the tags exist, but I can't see any way to interpolate text into the caption field based on any kind of computation whatsoever.
For reference, here are my current macro invocations:
<<tabs [list[]] state:$:/state/tabPeriod template:PeriodTemplate>>
<<tabs [list[$(currentTab)$]] state:$:/state/tabEvent class:"tc-vertical" template:"EventTemplate">>
<<tabs [list[$(currentTab)$]] state:$:/state/tabScene template:"SceneTemplate">>
All of these lines are from different templates, that just pull a list of tiddlers and template-transclude them into tabs using the provided template. Currently, the tabs are captioned with the tiddler caption, if defined, and fall back to the title. I'd like to alter the caption, ideally without inserting too much boilerplate into the tiddlers.

I figured out what I need to do differently: I defined a custom macro based on the tabs macro, added the logic, and now it works fine. I basically just changed the current contents of the caption logic to:
<$set name="tv-wikilinks" value="no">
<$transclude tiddler=<<currentTab>> field="caption">
<$macrocall $name="currentTab" $type="text/plain" $output="text/plain"/>
</$transclude>
<$list filter='[<currentTab>tag[light]]'>
○
</$list>
<$list filter='[<currentTab>tag[dark]]'>
●
</$list>
</$set>
I'm not sure if I'm using the list widget correctly, but it works.

Related

How to use the output of a tiddlywiki widget itself as a value for another wikitext expression?

Currently I'm trying to create a macro. The macro will be used within a $list widget which will cycle through a collection of tiddlers (chosen as per certain filter criteria which themselves aren't relevant here).
Within the above $list widget, for each tiddler, the macro will go through all of the fields of the tiddler that have a certain prefix (which is "link_"). These fields contain as their value internet URLs.
Not only do I wish to display these URLs (for each tiddler) as a list, I wish them to act as hyperlinks to said URLs.
Now so far the below macro has worked for the moment:
\define myMacro(prefix:"")
<$list filter="[fields[]prefix[$prefix$]sort[title]]" variable="fieldName">
<$transclude field=<<fieldName>>/>
</$list>
\end
What the above does is simply print the value (the URL) of that field while making sure it also acts as a hyperlink to that particular URL.
BUT
I wish to improve this further. Instead of the text of those links being the link itself, I want it to be a custom text.
For eg:
https://en.wikipedia.org/wiki/Computer_programming
vs.
Computer Programming (hyperlink to the same page but with custom hyperlink text)
But doing the above is seemingly impossible with the above $transclude method unless there is a way of using the output of a widget itself as a value.
I've already checked something direct like:
[[Custom link name|<$transclude field=<<fieldName>>/>]]
or
<a href=<$transclude field=<<fieldName>>/> >Custom link name</a>
Doesn't work.
I've tried other methods too but they don't work. How do they not work?
Let's say there is a variable in that particular tiddler called list_1 and it's value is https://en.wikipedia.org/wiki/Computer_programming. I wish to use the https://en.wikipedia.org/wiki/Computer_programming as the href value of an <a> tag.
But with all the methods I've tried, at best I can access the value list_1 itself via <<fieldName>>.
Only the $transclude method itself allows me to use the value of list_1 itself (ie https://en.wikipedia.org/wiki/Computer_programming), but it doesn't allow you AFAIK to use it as a value in an another wikitext expression.
So how do I achieve my aforementioned objective? Is there a way to use the output of a widget itself as a value for another wikitext expression or is there some other way to accomplish my objective?
Thanks in advance.
not sure I understand your goal but this is definately wrong:
<a href=<$transclude field=<<fieldName>>/> >Custom link name</a>
you should use the <$link widget to create links and a filter for attribute values
<$link to={{{[[title]get<fieldName>]}}}>Custom link name</$link>
or
<$link to={{{[<variableWithTitle>get<fieldName>]}}}>Custom link name</$link>
Edit: added title to filter

Trouble auto-generating list of links

I have a page in my Wiki (v5.1.17) that is supposed to auto-generate a list of links to tiddlers that need some sort of follow up. What shows up is whatever fulfils one of two criteria: tagged "needs_followup", or title begins with "/followup/".
Here is my code:
<$list filter="[prefix[/followup/]] [tag[followup_needed]] +[sort[title]]" variable=entry>
<$link><<entry>></$link><br/>
</$list>
The list of items works fine actually, except that they're not clickable links. They look like links -- blue and underlined -- but clicking on one doesn't actually do anything. Can anyone please tell me what I'm doing wrong?
The list of items works fine actually, except that they're not clickable links.
The problem arises because you have changed the variable in which the list widget stores titles. Usually the list widget stores the current title in a variable named <<currentTiddler>>:
This variable name is well known by other widgets, e.g. the link widget will look for this variable when no to attribute is specified.
However, your list widget instance stores the current title in a variable named entry, which is not understood by the <$link> widget.
They look like links -- blue and underlined -- but clicking on one doesn't actually do anything.
Actually, they are "real" links and also navigate once clicked: The link widget will resolve the tiddler where your code is in as <<currentTiddler>> and try to link to this tiddler (which looks like it is not linking at all because you probably have no scroll effect).
Can anyone please tell me what I'm doing wrong?
Solution 1) Hence the solution is to add the to-attribute and set it to <<entry>>:
<$list filter="[prefix[/followup/]] [tag[followup_needed]] +[sort[title]]" variable=entry>
<$link to=<<entry>>><<entry>></$link><br/>
</$list>
Solution 2) Instead of setting to you could also do the following:
<$list filter="[prefix[/followup/]] [tag[followup_needed]] +[sort[title]]" variable=entry>
<$set name="currentTiddler" value=<<entry>>>
<$link><<entry>></$link><br/>
</$set>
</$list>
Solution 3) Or you could remove the variable=entry altogether
<$list filter="[prefix[/followup/]] [tag[followup_needed]] +[sort[title]]">
<$link><<currentTiddler>></$link><br/>
</$list>
Offtopic: you may also want to use the $view widget to render the title to avoid auto wikification of PascalCase titles as links: <$link to=<<entry>>><$view field="title" /></$link>

How to apply formatting to content of a span

With CkEditor, When I create an A tag and later apply some custom formatting (like color text for instance), the resulting source looks like this:
<p><span style="color:#1abc9c;">some text</span></p>
As you can see, the formatting is around the text but INSIDE the A tag.
I have a personal plugin that outputs a SPAN tag with a specific class. In the wysiwyg editor, when I select the text and apply the same formatting, I get this:
<p><span style="color:#1abc9c;"><span class="command3d">Some text</span></span></p>
This time, the formatting is not simply around the text. It is applied around the SPAN tag.
How can I control this behaviour? I would like to get this result instead:
<p><span class="command3d"><span style="color:#1abc9c;">Some text</span></span></p>
Thanks
Unfortunately there is no ability to control the order of inline styles (based on span tags) inside editor's instance. The only sensible way to achieve desired result is to start with applying text color and then apply your custom style.
However there are two methods to convert output of the editor to the correct format. The first is to add custom handler to editor's data processor via toDataFormat event to check ancestors of span.command3d and swap them in places if necessary. However it's a little bit troublesome as you must traverse through all content, therefore it's easier way: add element callback to editor's filter. Example.

How to setup Table of Content in TiddlyWiki

If I go TiddlyWiki site I can see tab Content. How can I create my own table of content for my tiddlywiki file?
I found the documentation for this really confusing, but here's what I did that works best:
<div class="tc-table-of-contents">
<<toc-selective-expandable 'TableOfContents' sort[ind]>>
</div>
Then, tag each tiddler with TableofContents.
Lastly, when editing each tiddler, add a new field named "ind" (for index - you can change this to whatever you like, so long as it's not being used elsewhere, of course). Assign a value to "ind" starting with 0 to tell it what order you want the tiddlers to go in. I incremented by 10 instead of 1 in case I want to rearrange a few things or insert more in the middle.
Create a new tiddler and give the title Contents
Under tags, give the value $:/tags/SideBar
Under type the text for this tiddler, give
<$list filter={{$:/core/Filters/AllTiddlers!!filter}} template="$:/core/ui/ListItemTemplate"/>
This is explained in the documentation.
The short version: Add some tag (e.g. Content) to the pages you want to appear in the TOC; then in the place where you want it to appear, use one of the macros with that tag name (e.g. <<toc Content>>). To make a nested TOC, tag pages with the names of tags that appeared at the top level. So for example if you have a tiddler named First that is tagged with Content, then you can tag more tiddlers with First, and they will appear indented below First in the TOC.

how to disable tag validation in ckeditor?

CKeditor apparently automatically creates matching end tags when you enter a start tag. Is there a way to turn this behavior off?
I have a situation where I am creating two blocks of text in an admin program using CKeditor, then I'm using these to paint a page with the first block, some static content, and then the second block. Now I've got a case where I want to wrap the static content in a table. I was thinking, No problem, I'll just put the <table> tag in the first block and the </table> tag in the second block, and the static content will be inside the table. But no, CKeditor insists on closing the table tag in the first block.
In general, I can go to source mode and enter HTML directly, but CKeditor then decides to reformat my tagging. This seems to rather defeat the purpose of having a source mode. (I hate it when I tell the computer what I want and it tells me, No, you're wrong, I know better than you what you want!)
CKEditor produces valid HTML. Valid HTML has to include both - start and end tags. There's no way to change this behaviour without hacking editor. Note that even if you'll force editor to produce content without one of these tags it will then try to fix this and won't do this as you expect. E.g. load:
<p>foo</p></td></tr></table>
And you'll completely loose this table so only regexp based fix on data loading could help. In the opposite case:
<table><tr><td><p>foo</p>
You'll end up with paragraph wrapped with table, so it's better. But what if someone would remove this table from editor contents?
Therefore you should do this integration outside editor - prepend table to contents of one editor and append to contents of second one. You simply cannot force editor to work on partial HTML.

Resources