Dictionary tiddler and macro funkiness

249 views
Skip to first unread message

David Allen

unread,
Dec 28, 2015, 7:48:05 PM12/28/15
to TiddlyWiki
Here's my setup:

I have some tiddlers that describe an event in which a planet, in some way, joins an interstellar power.  Said tiddlers have a user-friendly description, along with three fields:
 - jointype: describes the method by which a planet joined an empire.  Examples include join, conquer, colonize.
 - planet: the tiddler of the associated planet.  [[Earth]], for example.
 - year: the year it happened.
 - faction: the power that now controls the planet.

I also have a tiddler called EmpireEventLookupTable, which is a dicitonary tiddler with the following information:
 - join: joined the
 - conquer: was conquered by the
 - colonize: was colonized by the

The idea behind this tiddler is to use it to present information in a more user-friendly manner.

Here's where I really use the stuff.

I'm trying to collect information about which planets joined which empires and when.  I can limit the information down to specific empires, but haven't implemented that yet.

Here's what I want to do:

  • In 2161, Earth joined the United Federation of Planets
  • In 2192, Regreea was conquered by the Nausicaan Empire
  • In 1961, Revanix II was conquered by the Interstellar Condordium
  • etc.

Here's what I do have:

\define empire_lookup(jointype)
{{EmpireEventLookupTable##$jointype$}}
\end

<$list filter="">

* In {{!!year}}, {{!!planet}} <<empire_lookup {{!!jointype}}>> {{!!faction}}

</$list>


This is the result:

  • In 2161, Earth {{EmpireEventLookupTable##join}} United Federation of Planets
  • In 2192, Regreea {{EmpireEventLookupTable##conquer}} Nausicaan Empire
  • etc.

In the output, the EmpireEventLookupTable in the result is a link to the tiddler, whereas join, conquer, etc is just appearing as plain text.


I think I'm really close to solving this, but I'm not sure how to solve this hiccup.  Anyone know what I should do?

David Allen

unread,
Dec 28, 2015, 11:53:46 PM12/28/15
to tiddl...@googlegroups.com
Nevermind, figured it out.  I had to use a set and widget thing and I had a syntax problem, so I got it to work.

--
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/1NbjFgAAUkU/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/98b79ccc-7a76-48c6-9dc6-88835da7e849%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
David Allen

Tobias Beer

unread,
Dec 29, 2015, 5:09:52 AM12/29/15
to tiddl...@googlegroups.com
Hi David,
 
Nevermind, figured it out.  I had to use a set and widget thing and I had a syntax problem, so I got it to work.

At your level of complexity it would really help to see a working example / demo... both to begin with and possibly also later. It's complex setups like yours people can learn the most from... if given some clues as to where to begin and how to decipher it all.

Best wishes,

Tobias. 

David Allen

unread,
Dec 29, 2015, 10:40:37 AM12/29/15
to tiddl...@googlegroups.com
Actually, as it stands, it doesn't do much.  Is there a way I can access a tiddler's fields within the tiddler?  For example, if a tiddler has a planet field, is there some way I can put the planet field into the tiddler's text field?

On Tue, Dec 29, 2015 at 4:09 AM, Tobias Beer <beert...@gmail.com> wrote:
Hi David,
 
Nevermind, figured it out.  I had to use a set and widget thing and I had a syntax problem, so I got it to work.

At your level of complexity it would really help to see a working example / demo... both to begin with and possibly also later. It's complex setups like yours people can learn the most from... if given some clues as to how to decipher it all.

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/1NbjFgAAUkU/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,
Dec 29, 2015, 11:15:00 AM12/29/15
to tiddl...@googlegroups.com
Hi David,
 
Actually, as it stands, it doesn't do much.  Is there a way I can access a tiddler's fields within the tiddler?  For example, if a tiddler has a planet field, is there some way I can put the planet field into the tiddler's text field?

Most certainly. It's called transclusion and in the simplest form it looks like:

{{!!planet}}

Best wishes,

Tobias. 

David Allen

unread,
Dec 29, 2015, 11:17:08 AM12/29/15
to tiddl...@googlegroups.com
I'm dumb.  I didn't actually add the parameter to the tiddler I was testing with so it never showed.  Thanks!

On Tue, Dec 29, 2015 at 10:15 AM, Tobias Beer <beert...@gmail.com> wrote:
Hi David,
 
Actually, as it stands, it doesn't do much.  Is there a way I can access a tiddler's fields within the tiddler?  For example, if a tiddler has a planet field, is there some way I can put the planet field into the tiddler's text field?

Most certainly, it's called transclusion and in the simplest form it looks like:

{{!!planet}}

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/1NbjFgAAUkU/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,
Dec 29, 2015, 11:27:11 AM12/29/15
to tiddl...@googlegroups.com
 Hi David,

I didn't actually add the parameter to the tiddler I was testing with so it never showed.  Thanks!

Happens to the best of us. Unlike the current release, the next release will always add any new field info entered into the editor. So, this problem should not pop up any more, i.e. the one where you create a new tiddler and at the bottom of it or in the tags-field find some already entered text hinting at the possibility that you recently forgot to hit some "add" button.

For example, on prerelease, try creating a new tiddler and...
  • enter some new tag value, but don't add it
  • enter some new field values, but don't add it
  • save the tiddler
You should find that both the new tag and field values have been saved to the tiddler.

Best wishes,

Tobias.

David Allen

unread,
Dec 29, 2015, 1:19:42 PM12/29/15
to tiddl...@googlegroups.com
So this is the solution I have to this problem:

\define empire_lookup()
{{EmpireEventLookupTable##$(thejointype)$}}
\end

<$set name=thejointype value={{!!jointype}}>
{{!!planet}} <<empire_lookup>> <$link to={{!!faction}}><$view field=faction></$link>
</$set>

Fields:
faction: United Federation of Planets
jointype: join
planet: [[Mars]]
year: 2162

The result is:
Mars joined the United Federation of Planets


The idea behind using this format is so I can put the body of the text into a template tiddler and use a form to create new empire event tiddlers quickly and easily.  It works for the most part.

I still have two issues with this:

In the form tiddler I have this:
Planet: <$select field='planet'>
<$list filter="[tag[planet]]">
<option><<currentTiddler>></option>
</$list>
</$select>

....

<$button>New Event
<$action-setfield $tiddler="Template: Empire Event" title=Event_{{!!year}}_{{!!month}}_{{!!day}}/>
<$action-setfield $tiddler=Event_{{!!year}}_{{!!month}}_{{!!day}} year={{!!year}} planet={{!!planet}} faction={{!!faction}} jonitype={{!!jointype}}/>
</$button>

year, month, day, faction, and jointype are defined with similar select widgets and are working fine.

Here are the problems.
Planet is showing up in the resulting tiddler as text only and not as a link to the associated tiddler.  For example, if I select Cardassia Prime from the select widget, the planet field in the resulting tiddler will say Cardassia Prime, when I need it to say [[Cardassia Prime]].  I'm not entirely certain how to accomplish this.

Another problem is in the title of the new tiddler.  I want the values of the year, month, and day fields to show up in the title of the new tiddler, but instead the tiddler name is Event_{{!!year}}_{{!!month}}_{{!!day}}, rather than Event_2451_12_14, for example.

Does anyone know how I can fix these issues?


On Tue, Dec 29, 2015 at 10:27 AM, Tobias Beer <beert...@gmail.com> wrote:
 Hi David,

I didn't actually add the parameter to the tiddler I was testing with so it never showed.  Thanks!

Happens to the best of us. Unlike the current release, the next release will always add any new field info entered into the editor ...so this problem should not pop up any more ...the problem where you create a new tiddler and at the bottom of it or in the tags-field find some already entered text hinting at the possibility that you recently forgot to hit some "add" button.

For example, on prerelease, try creating a new tiddler and...
  • enter some new tag value, but don't add it
  • enter some new field values, but don't add it
  • save the tiddler
You should find that both the new tag and field values have been saved to the tiddler.

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/1NbjFgAAUkU/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,
Dec 29, 2015, 2:40:17 PM12/29/15
to TiddlyWiki
Hi David,
 
Planet is showing up in the resulting tiddler as text only and not as a link to the associated tiddler.  For example, if I select Cardassia Prime from the select widget, the planet field in the resulting tiddler will say Cardassia Prime, when I need it to say [[Cardassia Prime]].  I'm not entirely certain how to accomplish this.

At what point do you need it to be a "listified" value? As you already do, instead of just {{!!planet}} you can always do <$link to={{!!planet}}><$view field="planet"/></$link>... or use a template / macro to simplify this.

Another problem is in the title of the new tiddler.  I want the values of the year, month, and day fields to show up in the title of the new tiddler, but instead the tiddler name is Event_{{!!year}}_{{!!month}}_{{!!day}}, rather than Event_2451_12_14, for example.

You need to call some helper macro(s) using the MacroCallWidget to properly construct the desired attribute value, e.g.

\define addJoinEvent(year,month,day)
<$some-widget some-title-attribute="Event_$year$_$month$_$day$"/>
\end

<$macrocall $name="addJoinEvent" year={{!!year}} month={{!!month}} day={{!!day}}/>

Best wishes,

Tobias.

David Allen

unread,
Dec 29, 2015, 2:52:07 PM12/29/15
to tiddl...@googlegroups.com
The planet field in the resulting event tiddler has to be a link because it has to match the planet fields of any species tiddlers which might have their planet field match the event's planet field.  Since I'm also doing stuff with the planet tiddlers and species tiddlers that uses the listed operator of a filter expression, and some of the planet names have spaces, I had to surround all the planet names with double square brackets for things to work.

I'll take a closer look at the title building widget later.

--
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/1NbjFgAAUkU/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,
Dec 29, 2015, 3:12:14 PM12/29/15
to tiddl...@googlegroups.com
What about doing something where, if a tiddler with a certain title exists, create one with an incremented number after it, similar to how the New Tiddler button works?  Does anyone know how I could do that?
--
David Allen

Tobias Beer

unread,
Dec 30, 2015, 1:38:58 AM12/30/15
to TiddlyWiki
Hi David,
 
What about doing something where, if a tiddler with a certain title exists, create one with an incremented number after it, similar to how the New Tiddler button works?  Does anyone know how I could do that?

Take a look at tobibeer/make.

Best wishes,

Tobias.

David Allen

unread,
Dec 30, 2015, 2:29:15 PM12/30/15
to tiddl...@googlegroups.com
Well, that worked, but I'm still having the problem where I can't get the planet name to be stored correctly.

--
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/1NbjFgAAUkU/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,
Dec 31, 2015, 2:37:59 AM12/31/15
to tiddl...@googlegroups.com
I don't know how in-depth you want me to go into regarding an explanation of how I'm using your make plugin, so here goes.

I have a setup where I store individual historical events in individual tiddlers.  The events have the following naming convention:

Event_YYYY_MM_DD_X, where YYYY is the year, MM is the month, DD is the day, and _X is optionally added, incrementing from one, when a tiddler with the same date already exists, similar to how new tiddlers are named when using the plus button.

The setting I'm working in is the Star Trek universe, designed so I can have an extensive database of background information for use in fan fiction.  I have things like species, governments, planets, etc stored in their own tiddlers.

I wanted to create an easy way to compile which species, planets, and star systems belong to which governments inside the corresponding government's tiddler.  Since planets can change hands, and since I wanted a way to compile all historical events into a single History tiddler, I made event tiddlers tagged with empire_event to denote events where a planet changed hands with regard to which government controlled it.  This worked fine, but I wanted to make things easier.  What I created was a form that would create a new tiddler, based on a template tiddler, and modify the fields in the new tiddler to reflect the values in the form.  All the template tiddler does is presents the fields in a user-friendly manner.  I can show how this is done if anyone wants me to.

Here is the form code bit-by-bit with explanations:

Planet: <$select field='planet'>
<$list filter="[tag[planet]sort[title]]">

<option><<currentTiddler>></option>
</$list>
</$select>

This creates a selection box that modifies a field in the form's tiddler called planet.  The list widget selects tiddlers tagged with the planet tag, sorts them by title, and adds them as options to the selection box.

Action:
<$select field='jointype'>
<$list filter="join conquer colonize found destroy breakfree cede">

<option><<currentTiddler>></option>
</$list>
</$select>

Similar to the planet selection box, but this uses an explicitly-defined list of possible ways a planet can join or leave a government, and can be modified if needed.

Faction:
<$select field='faction'>
<$list filter="[tag[faction]sort[title]]">

<option><<currentTiddler>></option>
</$list>
</$select>

Identical to the planet selection box, except that it handles governments.

Year:
<$edit field="year" placeholder="year" />

Month:
<$select field='month'>
<$list filter="01 02 03 04 05 06 07 08 09 10 11 12">

<option><<currentTiddler>></option>
</$list>
</$select>

Day:
<$select field='day'>
<$list filter="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31">

<option><<currentTiddler>></option>
</$list>
</$select>

This allows me to enter the date an event occurred.  Since the year has infinite range, I chose to go with a simple text box instead of a selection box.

!!!Same-Year Events
<$list filter="[tag[event]] [tag[empire_event]] +[year{!!year}sort[title]]">

*<$link to=<<currentTiddler>>><<currentTiddler>></$link>:{{}}

</$list>

This compiles a list of any events that occurred the same year, allowing me a way to determine with greater accuracy when an event would make sense to have occurred.  It gets all tiddlers tagged event, all tiddlers tagged empire_event, then picks only those whose year matches the value in the year box, then sorts them by title to put them in chronological order.  The line within the list widget simply creates a link to the event tiddler, adds a colon, then transcludes the event tiddler, since the event tiddler is usually only one line of text.  This allows me to see the date and contents easily while letting me quickly make changes when necessary.

Now where the heavy lifting comes in.

<$set name=eventtitle filter="[make[Event_{{!!year}}_{{!!month}}_{{!!day}}\max:1 \ sep:_]]">

This creates a variable called eventtitle and uses a filter to return a link to a new, undefined tiddler.  It uses Tobias Beer's make plugin.

Here's how it works:
Everything before the first backslash, that being Event_{{!!year}}_{{!!month}}_{{!!day}}, is a prefix for any tiddler titles the make plugin creates.  If I had year set to 2011, month to 07, and day to 22, the prefix for the titles created by the make plugin would be Event_2011_07_22.  The "\max:1" tells the make plugin to only generate one link, since I'm only creating one tiddler at a time.  The "\sep:_" tells the plugin to use an underscore as a separator between the prefix and any number appended to the title.  For example, if I have two events occuring on 07 22 2011, the second tiddler created by the form would have the title Event_2011_07_22_1, the third Event_2011_07_22_2, etc.

<$button>New Event
<$action-setfield $tiddler="Template: Empire Event" title=<<eventtitle>>/>

<$action-setfield $tiddler=<<eventtitle>>  year={{!!year}} planet={{!!planet}} faction={{!!faction}} jointype={{!!jointype}}/>

</$button>
</$set>

This creates a button which performs two actions.
The first is where it duplicates the tiddler named Template: Empire Event and sets the title of the duplicate to the eventtitle variable I made earlier.
The second is where it sets the fields of the new tiddler to match the values in the form.

This form allows me to select a planet, an action, and a government, then specify the date, and create a new tiddler that fits in well with other things I have going on in my workspace.

--
David Allen

Tobias Beer

unread,
Dec 31, 2015, 5:18:09 AM12/31/15
to TiddlyWiki
Hi David,

I don't know how in-depth you want me to go into regarding an explanation of how I'm using your make plugin, so here goes.

Wow.

Be sure that I wouldn't have expected for you to detail every single turn. :-)

It can be quite a challenge to communicate or translate functional aspects of an idea / concept — your Start Trek universe — to TiddlyWiki lingo on the one hand ...or to understand any TiddlyWiki lingo presented as an answer on the other.

So, kudos to the clarity with which you have described getting from A to Z, conceptually, functionally and implementation-wise.

While possibly tl dr for many, it's pretty easy for anyone to follow what you tried to do and how you eventually achieved it ...and gives quite a hands-on description of achieving a slightly complex setup / ui / workflow, TiddlyWiki-style.

Best wishes,

Tobias. 

Felix Küppers

unread,
Dec 31, 2015, 8:15:27 AM12/31/15
to tiddl...@googlegroups.com
Hi David

You can use Tobias' make plugin to iterate over numbers till 31 using
count and max variables

> <$list filter="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18
> 19 20 21 22 23 24 25 26 27 28 29 30 31">

@Tobias maybe the make filter can have a parameter that tells it how
many digits a number should have so count adds leading zeros if the
integer is too small.
E.g. countpad=3 then count is 001 in the first iteration instead of 1.
Not sure how to name this param maybe padDigits, countpad, padlength,
leftpad…

-Felix

Tobias Beer

unread,
Dec 31, 2015, 10:00:27 AM12/31/15
to TiddlyWiki
Hi Felix,

You can use Tobias' make plugin to iterate over numbers till 31 using
count and max variables

Haven't thought of that. ;-)

Zero-padding the count sounds like a good option.
I went ahead and implemented it as announced here.

As for David, to generate the zero-padded 31 digits you could use:

<$list filter="[[]make[%count%\max:31\pad:2]]"/>

instead of:

<$list filter="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31"/>

Best wishes,

Tobias.

Felix Küppers

unread,
Dec 31, 2015, 10:18:59 AM12/31/15
to tiddl...@googlegroups.com
Sweet!
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, 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.

David Allen

unread,
Dec 31, 2015, 10:40:28 AM12/31/15
to tiddl...@googlegroups.com
Was the make plugin recently updated?  The pad part isn't working for me.

--
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/1NbjFgAAUkU/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,
Dec 31, 2015, 10:46:47 AM12/31/15
to tiddl...@googlegroups.com
I also have two small problems.  I need the planet field that's passed in the second action widget to be the name of the planet surrounded in dual square brackets, but whatever I try doesn't work.  Is there a way I can escape the square brackets or concatenate strings to get them to be constructed into a string correctly?
--
David Allen

Tobias Beer

unread,
Jan 1, 2016, 5:55:14 AM1/1/16
to tiddl...@googlegroups.com
Hi David,
 
Was the make plugin recently updated?  The pad part isn't working for me.

Indeed, I actually went straight ahead and implemented zero padding
as per Felix' suggestion (announced here).

So, yes that's new functionality so you need to update make plugin.

Best wishes,

Tobias.
Reply all
Reply to author
Forward
0 new messages