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

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

Related

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>

Dynamically change caption field (or just title in tabs macro) in 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.

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 can I query XPath matching an attribute from one tag against another attribute from another tag?

I'm scripting a web app that has labels for input fields. EG:
<label for="surname">Family Name:</label>...<input id="surname" ...></input>
I'd like to be able to write an XPath expression that takes the text "Family Name:" to match the label, then takes the "for" attribute from the label and uses that to find the associated input tag by matching its "id" tag.
I can make this "work" as follows:
//label[contains(.,"Family Name:")]/following::input[1]
However, for this web app I think it would be more reliable to match for/id. (EG: How can I be sure that in all possible layouts the first input tag following the label is the one I want? And what happens if somewhere down the line this page is rendered using a right-to-left script?
My ultimate aim is to create a library function that we can use to write QA scripts in advance of web pages to test against, when all we have is a picture or document with an input field labelled "Family Name:" and no idea what id some programmer will ultimately assign to the field.
Maybe this is what you're looking for?
//input[#id = //label[contains(., "Family Name:")]/#for]
As for your ultimate goal, you may want to take a look at the XPath gem for Ruby. Some of what you're doing may already be implemented there. (Specifically, check out the library's HTML Helpers)

Multi-language store- Changing custom menu's language dynamically

I am doing Multi-language store in magento. i have some custom menu in header section like how to order, Help etc. .
now currently these menu i have given direct link like
<li>Help</li>
<li>how to order</li>
i am not sure how multi-language feature will work with this menu.. How can i write these top menu as if It will change with language change.
any suggestions will be helpful for me.
thanks
Any text that is hard-coded into your template needs to be wrapped in the translation helper.
echo $this->__('Help');
But make sure the block it applies to has a helper declared, otherwise you'll need to load the generic helper.
Mage::helper('core')->__('Help')
Then, you can edit the relevant translation CSV file. By putting "Help" in the first column, and the translation in the second column.
Although, you'll be able to use translate in-line once you are using the above PHP.

Resources