Square brackets, transclusion, and widget problem

147 views
Skip to first unread message

David Allen

unread,
Jan 2, 2016, 11:32:51 PM1/2/16
to TiddlyWiki
In my setup, I use the following filter:

[tag[star_system]quadrant[$quadrant$]listed[solar_system]listed[planet]tag[species]sort[title]]

What this does is gets all solar systems whose quadrant value matches the value passed into the macro this filter is in, then goes through two listed parts to get tiddlers whose planet values are in the solar systems, select only the species tiddlers, then sort them by title.  Since all solar systems and some planets have spaces in their names, all solar_system and planet field values must be surrounded in [[ ]] for the listed part of the filter to work.  If this is wrong, please let me know.

Since the square brackets must be around the planet and solar system names, I need to be able to set the solar system and planet fields in certain tiddlers with names surrounded by two pairs of square brackets ( [[Cardassia Prime]] instead of Cardassia Prime, for example).  Using a link widget will not work in this circumstance.

I have a form that lets me create new tiddlers based on a template empire event tiddler, and one of the fields that I manipulate is a planet field.  The values of the planet field in these empire event tiddlers and the species tiddlers must be able to match up, meaning they need a pair of square brackets.  The problem is, when I set the value of these form elements, a planet name comes up as simple text rather than a bracketed link (Rura Penthe instead of [[Rura Penthe]]).  I pass the value of the form into an action-setfield widget by using a targetField={{!!formField}} format (planet={{!!planet}}, for example).

The problem is, the value that shows up in the new event tiddler does not contain the square brackets, which makes it not work with the filter above.  What I'd like is some way to construct a string that has square brackets along with the field value and can be passed into a widget and work correctly.

When I do [[{{!!planet}}]], the result is exactly that string, [[{{!!planet}}]].  When I try to put it into a widget, it comes up as [[$parameter$]].  I'd like to find a way to construct a string literal, but I'm not sure how to do so.

Can anyone help me with this?

Eric Shulman

unread,
Jan 3, 2016, 12:08:08 AM1/3/16
to TiddlyWiki
On Saturday, January 2, 2016 at 8:32:51 PM UTC-8, David Allen wrote:
The problem is, the value that shows up in the new event tiddler does not contain the square brackets, which makes it not work with the filter above.  What I'd like is some way to construct a string that has square brackets along with the field value and can be passed into a widget and work correctly.

When I do [[{{!!planet}}]], the result is exactly that string, [[{{!!planet}}]].  When I try to put it into a widget, it comes up as [[$parameter$]].  I'd like to find a way to construct a string literal, but I'm not sure how to do so.

Can anyone help me with this?

You can use the <$set> widget with the title filter.  This will add brackets to the field value if it contains spaces.  The result can be passed into a widget param.  For example:
<$set name="result" filter="""[title{!!somefield}]""">
<$text text=<
<result>>/>
</$set>

let me know if this helps

enjoy,
-e

David Allen

unread,
Jan 3, 2016, 12:42:59 AM1/3/16
to tiddl...@googlegroups.com
That mostly worked.  The only problem now is with the template tiddler I used to create the new event tiddlers.

Here's the body of the tiddler:

\define empire_lookup()
{{EmpireEventLookupTable##$(thejointype)$}}
\end
<$set name=thejointype value={{!!jointype}}>
{{!!planet}} <<empire_lookup>> <$link to={{!!faction}}><$view field=faction></$link>

</$set>

With planet names that contain spaces, there's no problem.  With ones that don't, the name doesn't show up as a link

My solution was to replace the {{!!planet}} part with <$link to={{!!planet}}>{{!!planet}}</$link>.  Functionally, this works, but planets with a space in the name have the link show up as a missing tiddler link, because it's trying to find a tiddler whose title contains square brackets.  I can click on the part that {{!!planet}} renders as and bring up the planet tiddler, but I'd like it so it doesn't look like I have a bunch of missing tiddlers where I do not.


--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/YpM4Jw8nkdU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/2b161ac9-b96d-492c-a651-716d499a7ace%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
David Allen

Tobias Beer

unread,
Jan 3, 2016, 11:47:41 AM1/3/16
to TiddlyWiki
Hi David,

I believe you can use my plugin tobibeer/setvars to properly store a list item in a variable, e.g.

<$setvars _planet={{!!planet}} planet="planet[1]">
<$link to=<
<planet>>><<planet>></$link>
</$setvars>

Best wishes,

Tobias.


David Allen

unread,
Jan 3, 2016, 10:04:30 PM1/3/16
to tiddl...@googlegroups.com
Really, the only thing I need now is a way to override the formatting used with the <$link> widget, so that the link doesn't appear to be missing.  Since the link widget I'm using is linking to {{!!planet}} and the planet field is the planet name surrounded by dual square brackets, what its trying to link to doesn't exist, but I'm using {{!!planet}} as the text for the link, and the inner text works fine.

I just need a way to override the link widget's formatting now.  Otherwise Eric Shulman's solution works beautifully.

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/YpM4Jw8nkdU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

For more options, visit https://groups.google.com/d/optout.



--
David Allen

Tobias Beer

unread,
Jan 4, 2016, 1:27:17 AM1/4/16
to tiddl...@googlegroups.com
Hi David,
 
I just need a way to override the link widget's formatting now.  Otherwise Eric Shulman's solution works beautifully.

Unfortunately, that is not true. Although you may feel like you can avoid retrieving the title using a variable, you do need a proper reference and [[Some Title]] is not while Some Title is.

The one thing I could think of is to not use any link widget at all but to transclude the planet field as is, since it already does contain the link notation, e.g. [[Some Title]]... so simply inserting that via {{!!planet}} should produce a link, e.g.:

title: any title
planet
: [[Some Planet]]

{{!!planet}} <= this will be a link!

However, using an editor equivalent to the tags editor, any values that do not contain spaces will be saved without double square brackets, so...

title: any other title
planet
: Earth

{{!!planet}} <= this will NOT be a link!

So, as I or Eric suggested, you do need to retrieve the given item from a list-field and store it in a variable ...to be able to properly construct the link using the link widget.

Ergo: It is not simply a matter of styles / formatting.

Best wishes,

Tobias.

David Allen

unread,
Jan 6, 2016, 11:27:18 AM1/6/16
to tiddl...@googlegroups.com
Your suggestion is having the same problem as the solution I came up with, unless I'm not understanding what you're doing.

Here's what I've got:

<$setvars _aplanet={{!!planet}} theplanet="aplanet[1]">
<link to=<<theplanet>>><<theplanet>></$link>
</$setvars>



On Mon, Jan 4, 2016 at 12:27 AM, Tobias Beer <beert...@gmail.com> wrote:
Hi David,
 
I just need a way to override the link widget's formatting now.  Otherwise Eric Shulman's solution works beautifully.

Unfortunately, that is not true. Although you may feel like you can avoid retrieving the title using a variable, you do need a proper reference and [[Some Title]] is not while Some Title is.

The one thing I could think is to not use any link widget at all but to transclude the planet field as is, since it already does contain the link notation, e.g. [[Some Title]]... so simply inserting that via {{!!planet}} should produce a link, e.g.:

title: any title
planet
: [[Some Planet]]

{{!!planet}} <= this will be a link!

However, using an editor equivalent to the tags editor, any values that do not contain spaces will be saved without double square brackets, so...

title: any other title
planet
: Earth

{{!!planet}} <= this will NOT be a link!

So, as I or Eric suggested, you do need to retrieve the given item from a list-field and store it in a variable ...to be able to properly construct the link using the link widget.

Ergo: It is not simply a matter of styles / formatting.

Best wishes,

Tobias.

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/YpM4Jw8nkdU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

For more options, visit https://groups.google.com/d/optout.



--
David Allen

David Allen

unread,
Jan 6, 2016, 11:54:14 AM1/6/16
to tiddl...@googlegroups.com
I think I figured it out using the set widget.

<$set name=redoneplanet filter="[prefix[{!!planet}]]" value="<$link to={{!!planet}}>{{!!planet}}</$link>" emptyValue={{!!planet}}>
<<redoneplanet>>
</$set>

This way, when the planet field does not have square brackets, a link is created to the tiddler of the same name.  If it does have brackets (and as a tiddler title doesn't exist), then it is simply transcluded as-is.
--
David Allen

Tobias Beer

unread,
Jan 6, 2016, 3:04:35 PM1/6/16
to TiddlyWiki
Hi David
 
I think I figured it out using the set widget.

Your example doesn't work for me if I put it into a tiddler tagged $:/tags/ViewTemplate on tiddlywiki.com

This one does:

<$set name=planet
filter="[{!!planet}get[title]]"
emptyValue="{{!!planet}}"

value="<$link to={{!!planet}}>{{!!planet}}</$link>">
<<planet>>
</$set>

Best wishes,

Tobias. 

Tobias Beer

unread,
Jan 6, 2016, 3:09:14 PM1/6/16
to TiddlyWiki
Hi again, David,

I think the proper way to do it would be to use a template:

{{||$://templates/planet-link}}

and then:

title: $://templates/planet-link

<$list filter={{!!planet}}/>


Best wishes,

Tobias.
Reply all
Reply to author
Forward
0 new messages