In a Tiddler, how to list all its fields and their values? - tiddlywiki

Using TiddlyWiki, I'm trying to show, in a specific Tiddler, a subset of all the fields of that tiddler, with their values.
The problem is, while I'm able to list all the relevant fields' names, I cannot print their value.
My current code is:
<$list filter="[fields[]prefix[Result_]sort[title]]" template="$:/zx/ListFieldItemTemplate"/>
... which aims to list all the fields starting with Result_.
The (simplified) template $:/zx/ListFieldItemTemplate is:
<div>
<$view field="title"/>
</div>
My fear is that the list widget is only sending the names of the fields, not the values, which means there's no way to get that value from the template. So I may need to somehow send the values, too. But I don't know how.

One possibility is to use a macro.
In your tiddler, put the following macro call:
<<myMacro prefix:"Result_">>
(The aim is to filter the fields only to those starting with "Result_".)
Then, create a new tiddler, whose name is not important, but which must contain the tag $:/tags/Macro to make that macro globally available. And in that tiddler, write the following code:
\define myMacro(prefix:"")
<$list filter="[fields[]prefix[$prefix$]sort[title]]" variable="fieldName">
<<fieldName>>
====
<$view field=<<fieldName>>/>
</$list>
\end
This will output something like:
Result_MyFieldName1 ==== MyFieldValue1
Result_MyFieldName2 ==== MyFieldValue2
Result_MyFieldName3 ==== MyFieldValue3
Result_MyFieldName4 ==== MyFieldValue4
Of course, you can then modify the macro to use your own formatting.

This is an old thread, but maybe someone will find this useful:
Loop through all fields and list name/value:
<$list filter="[fields[]] -[[title]] -[[text]] -[[tags]] -[[created]] -[[modified]]" variable="fieldname">
<> = <$view field=<> />
</$list>

Related

Is there a way to use xpath to search for a value where a part of the value dynamically changes?

I’m trying to match a value where I don’t necessarily know the whole value every time i.e. it's randomly generated. Is there a way to search for a value where a part of the value dynamically changes?
Please see my example of value I'm trying to find and my attempted xPath:
<div class="target" testid="target”>
<h2>Hi, random user</h2>
<p>To get the xpath <b>target</b> of <b>[text I don’t know]</b> in <b>[text I don’t know]</b>, you need to do the following</p>
</div>
I’ve tried the following xpath I picked up from another question but it don’t get a match:
//p[matches(.,'^To get the xpath <b>target</b> of <b>.*</b> in <b>.*</b>, you need to do the following$')]
I’ve tried different combinations with and without the bold tag but can’t seem to get it to match. truthfully I'm not sure I've got the right syntax...
Try the plain text in the second argument of matches e.g.
//p[matches(., '^To get the xpath target of .*? in .*?, you need to do the following$')]
Online sample here.
Why not to use contains() method using the fixed attribute value?
Something like:
//p[contains(.,'you need to do the following')]

How to use a logical operator in WikiText to select a tiddler with one OR another tag?

The TiddlyWiki documentation provides an example of the tag operator:
[tag[task]]
This selects all tiddlers that have been tagged as task.
How though would one select all tiddlers tagged with one OR another tag; so for instance I want to select all tiddlers that are tagged either dog or cat? None of the below attempts succeed:
[tag[cat]||[dog]]
[tag[cat]OR[dog]]
[tag[cat, dog]]
For context, I'm looking to use this within a list, along the lines of:
<$list filter="[tag[cat]||[dog]]">
<$view field="title"/>
</$list>
A bit late but in case it's still useful...
There are various ways to combine the results of different lists, and in this case one just needs the simple union of lists which is represented with a space between two filter expressions:
<$list filter="[tag[cat]] [tag[dog]]">
<$view field="title"/>
</$list>
The document about filters is rich but a bit messy, I think that this is explained in "Introduction to filter notation" but there are other relevant parts in "Filter expression", also here and possibly in other places.

Trying to find two different text nodes from a descendant

Someone decided to make a site as unfriendly as possible by intention so I'm trying what I can to have our scraper still get to where it should.
<div class="issueDetails">
<div class="issueTitle ng-binding" style="">FANCY UNIQUE TEXT dd.MM.yyyy</div>
<a>COMPLETELY DIFFERENT TEXT</a>
I've left out the unnecessary details here, but I'm trying to find a match within the site through XPATH (can't use anything else for this) that will find something which fulfils both conditions, FANCY UNIQUE TEXT dd.MM.yyyy *as well as COMPLETELY DIFFERENT TEXT.
I've tried my luck with //div[#class='issueDetails']/descendant::*[contains(text(), 'FANCY UNIQUE TEXT dd.MM.yyyy') and contains (text(), 'COMPLETELY DIFFERENT TEXT')]
but it contains the erroneous logic that both unique things I need are in the same thing.
The first, FANCY UNIQUE TEXT, is the unique identifier for where I want to go. The second, COMPLETELY DIFFERENT TEXT, is what I need the scraper to click on to actually head to that specific one. So an XPath that finds both despite them being different descendants is necessary.
Is this what you're looking for :
//div[#class="issueDetails"]/*[contains(.,"COMPLETELY DIFFERENT TEXT") or translate(substring(.,string-length(.)-9,10),"123456789","000000000")="00.00.0000" and contains(.,'FANCY UNIQUE TEXT')]
It will return the 2 elements respecting your conditions : div and a.
Translate, substring-length and substring functions are used to check if a date pattern is present in the div element.
EDIT : Check if the parent+child contains the text you're looking for, then get the childs with :
//div[#class='issueDetails'][contains(.,"FANCY UNIQUE TEXT dd.MM.yyyy") and contains(.,"COMPLETELY DIFFERENT TEXT")]/*[contains(.,"FANCY UNIQUE TEXT dd.MM.yyyy") or contains(.,"COMPLETELY DIFFERENT TEXT")]

Sort authors via last name in Tiddlywiki

It would be good to sort lists using an author's last name.
I have this code in one of the tiddlers, it lists all the tiddlers tagged 'author' and sorts alphabetically:
<$list filter='[tag[author]sort[title]]'>
</$list>
e.g.
Adam Robinson
Andrew Adonis
Benjamin Franklin
Dale Carnegie
Daniel Priestley
George Leonard
I would like the list to be sorted by last name, so it looks like this:
Adonis, Andrew
Carnegie, Dale
Franklin, Benjamin
Leonard, George
Priestley, Daniel
Robinson, Adam
Any ideas how to do this?
Easy option: Add a ByLastName field populated the way you want and sort on that.
Medium option: Introduce the notion of generated fields into tiddlywiki.
Hard option: Modify the sort filter to call a macro with whatever data you specify and then sort the original list based on the result.
In recent versions of TiddlyWiki, you can do this with the sortsub operator, which sorts based on the results of applying a filter expression to the inputs. Note that when you use this operator (or any other operator that takes a subfilter), you have to define the subfilter using a macro, or there's no way for TiddlyWiki to tell which square brackets are part of the main filter and which are part of the subfilter.
Here's a minimal working version:
\define myfilt() [split[ ]last[]]
<$list filter="[tag[author]sortsub<myfilt>]">
...
</$list>
To get the display to show up as "Lastname, Firstname", as in your example, rather than just showing the title of the tiddler as is:
\define myfilt() [split[ ]last[]]
<$list filter="[tag[author]sortsub<myfilt>]">
<$set name=formattedName value={{{ [all[current]split[ ]last[]addsuffix[, ]] [all[current]split[ ]butlast[]] +[join[]] }}}>
<$link to=<<currentTiddler>>><<formattedName>></$link><br>
</$set>
</$list>
We calculate the new format using a filter in {{{ triple curly braces }}} and assign it to a variable (note the use of butlast[] rather than first[] so that if someone has more than two names, the middle ones go on the end rather than disappearing). Then we create a link whose text is that new formatted version, and whose target is the original tiddler name.

FreeMarker specifc table index from results

I'm using openReports that uses freeMarker formats as a template.
The following:
<#display.table name="results" class="displayTag" sort="list" export=true pagesize=10 requestURI="queryReportResult.action">
<#display.column property="first_name" title="First Name" sortable=true headerClass="sortable" />
<#display.column property="last_name" title="Last Name" sortable=true headerClass="sortable"/>
</#display.table>
The data is automatically grabbed using a stored procedure.
This will create a sortable table, does anyone know how I could access just the first row of data. I intend to save it into a variable and output it in some part of the page.
The reason I want to do this is we have a basic report and what would make it perfect is if I could print some from it toward the top of the page above the report.
I know a lot of people aren't familiar with OpenReports, but I figured freeMarker does have a pretty good following. I understand if this is pretty obscure
From what I can see from here, the #display.table call prints the whole table at once, so there's nowhere to insert the FreeMarker code to catch the first row. But of course you should check the documentation of #display.table to see if it offers any helpful options. But, I suppose you have already done that. So as a last resort, you can capture the whole table into a variable with <#assign tableHTML><#display.table ...>...</#display.table></#assign> and then extract the first row with a regular expression (or something like that) from the value of the tableHTML variable.

Resources