Name formatting using caption field

153 views
Skip to first unread message

David Allen

unread,
Jan 9, 2016, 9:19:43 PM1/9/16
to TiddlyWiki
So I've got various different characters of various different species and various different ways in which a character's name is displayed.  I'd like to format how a character's name is displayed by using the caption field of a character tiddler.  I'm using a macro that uses Tobias's setvars widget, and it works when I put the macro call into the caption field and manually enter the parameters for the species and names for the characters.

Here's how it's working (Other species will be added eventually):

\define name_output(species,first,second,third)
<$setvars twothreename="""(\$third$\ ? \$third$, $first$ $second$\) || \$second$, $first$\""" formatted_name="""(\$species$\ == \Human\ ? twothreename ) || (\$species$\ == \Bajoran\ ? \$first$ $second$\) || (\$species$\ == \Garbrini\ ? \$second$, $first$ $third$\) || \$first$\""">
<<formatted_name>>
</$setvars>
\end

Here are the fields in an example character tiddler:

caption: <<name_output Human John Brown Doe>>
species: Human

This works fine so far.  Here's what I'd like it to do.
  1. Pass the title of the character tiddler into a macro, parse the title as a list, then pass the list to the name_output macro so I don't have to manually add the name fields to a bunch of already made character tiddlers.
  2. Use the species field in the caption field.  <<name_output {{!!species}} name1 name2 name3>> doesn't seem to work as it interprets the species parameter as {{!!species}} rather than the value of the species field, although <<name_output Human {{!!title}}>> doesn't have this problem.

Does anyone know how I can do this?

Tobias Beer

unread,
Jan 10, 2016, 4:54:51 AM1/10/16
to tiddl...@googlegroups.com
Hi David,

I'm a quite amazed to find you using setvars at that level of complexity. *bows down*
As for long expressions like yours, I'd possibly use plenty line-breaks and white-space for readability, e.g.:

\define name_output(species,first,second,third)
<$setvars
twothreename
="""
  (\$third$\ ? \$third$, $first$ $second$\) ||
  \$second$, $first$\
"""
formatted_name
="""
  (\$species$\ == \Human\ ? twothreename ) ||
  (\$species$\ == \Bajoran\ ? \$first$ $second$\) ||
  (\$species$\ == \Garbrini\ ? \$second$, $first$ $third$\) ||
  \$first$\
""">
<<formatted_name>>
</$setvars>
\end

Can you test and confirm that the above works? I think it should.

Here are the fields in an example character tiddler:

caption: <<name_output Human John Brown Doe>>
species: Human

As for using wikitext in fields. Be mindful that transcluding and reusing that at other places, e.g. in macros may have unexpected results in that the field value is not wikified before using. So, you're actually passing the string <<name_output Human John Brown Doe>>.

Therefore, I think what you need to do is:

Instead of using wikitext (macros) in fields directly,
have as many fields as are needed to create the proper output where you need it, elsewhere.
In other words, you should have fields like name-1st, name-2nd, name-3rd
and then have a macro outside of your field contents
that does your desired handling where ever you need it,
but not as the field value.

Does that make sense?

Also, whenever you need to pass an evaluated macro parameter,
use the MacroCallWidget... which I think you may not have been able to,
because putting that in your field contents may definitely break things elsewhere,
when you would expect the output text, but instead are actually retrieving the wikitext for the widget.

Best wishes,

Tobias.

David Allen

unread,
Jan 10, 2016, 11:54:11 PM1/10/16
to tiddl...@googlegroups.com
The white space part of the setvars works fine.  Thanks for that tip, should make it easier to add to later.

Out of curiosity, in what order are macros, text references, widgets, etc used?  I ask because I'm extremely close to getting a tiddler that can modify the large number of already-made character tiddlers to add a working caption field.
This email has been sent from a virus-free computer protected by Avast.
www.avast.com

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/NwaJdnB_yTU/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/73772a65-a91b-4112-8795-cfbaa90a0ac6%40googlegroups.com.

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



--
David Allen

Tobias Beer

unread,
Jan 11, 2016, 3:42:24 AM1/11/16
to tiddl...@googlegroups.com
Hi David,
 
Out of curiosity, in what order are macros, text references, widgets, etc used?

How do you mean "used"? Used where?

One thing's for sure, you cannot have a widget be an attribute to a widget.
So, you can have macros be an attribute to a widget,
but you cannot have a macrocall widget be an attribute to another widget
and thus dynamically evaluate macro parameters via other variables or text-references
unless your macro actually parses those themselves, e.g.

\define macro:(macro,1,2,3,4,5,6,7,8,9,10) <<$macro$ '''$1$''' '''$2$''' '''$3$''' '''$4$''' '''$5$''' '''$6$''' '''$7$''' '''$8$''' '''$9$''' '''$10$'''>>
\define text:(reference) {{$reference$}}

<<macro: version>>

<<macro: now YYYY0MM0YY>>

<<text: {[tag[HelloThere]]}>>

<<text: HelloThere>>

Macros really are text-substitution patterns,
the wikification is handled elsewhere
  • by some widget(s) it creates
  • or by the widget where a macro is used as an attribute
Also, Javascript or Wikitext macros have different refresh behavior hinted at:
Best wishes,

Tobias.

David Allen

unread,
Jan 11, 2016, 7:08:21 PM1/11/16
to tiddl...@googlegroups.com
I was wondering about the order in which those kinds of things are run.  For example, are widgets evaluated before or after macro calls?  I'm trying to figure this out so I know what I can use where and in what order TiddlyWiki will evaluate them.
This email has been sent from a virus-free computer protected by Avast.
www.avast.com

--
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/NwaJdnB_yTU/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 12, 2016, 2:23:40 AM1/12/16
to TiddlyWiki
Hi David, 

I was wondering about the order in which those kinds of things are run.  For example, are widgets evaluated before or after macro calls?  I'm trying to figure this out so I know what I can use where and in what order TiddlyWiki will evaluate them.

It all depends on how your wikitext is constructed.
The way things are nested defines execution order.
Generally, the parser creates a parse-Tree from wikitext
which is turned into a widget-Tree.
And those widgets may evaluate macros,
e.g. via their attributes or contents.

Best widgets, err wishes, ;-)

Tobias.
Reply all
Reply to author
Forward
0 new messages