passing "title" (or a field?) into macros in a template

220 views
Skip to first unread message

HansBKK

unread,
Jun 23, 2011, 3:24:16 AM6/23/11
to tiddl...@googlegroups.com
First the background:

I'd like to consolidate various categories of tiddlers on a given topic into a tabbed display. I've been putting something the following into menu-displayed tiddlers, substituting XYZ for a given "quality" - e.g. "Compassion"

----
<<tabs journalTypeTabs
[[XYZ definitions]] "Definitions of XYZ" [[XYZ Definitions]]
[[XYZ quotes]] "Quotes about XYZ" [[XYZ Quotes]]
[[XYZ relationships]] "Relations between XYZ and other Qualities" [[XYZ Relationships]]
[[XYZ statements]] "Statements about XYZ" [[XYZ Statements]]
[[XYZ archives]] "Archived items on XYZ" [[XYZ Archives]]
>>

Then in each of the target tiddlers I have something like this (this example is the [[XYZ Definitions]] tiddler, in this case showing various "Definitions of Compassion".

----
<<tiddler OpenTaggedTiddlers with: "Open these" "XYZ AND #Definition AND NOT #archived" modified reverse close>>
----
<<matchTags "   • [[%0]]" "\n" sort:-modified Compassion AND #Definition AND NOT #archived >>


Now (finally) my questions:

Rather than copying and pasting, then changing the relevant XYZ for each separate Quality manually, would it be possible to put this code into a template, and then pass in the title of the tiddler (or even better a field value? but I don't know anything about fields yet).

In other words something like "$1" to represent the title of the tiddler "Compassion" would be substituted for XYZ in the above two blocks of code.

At a higher level, since you understand the "bigger picture" of what I'm trying to accomplish (and thank you for reading this far!), can you suggest an easier or more elegant way, is there a package of plugins or a canned TW that does this sort of thing rather than my re-inventing the wheel? You can tell I'm a complete newbie to coding. . .

HansBKK

unread,
Jun 28, 2011, 3:49:12 AM6/28/11
to tiddl...@googlegroups.com
Sorry for bumping, but I've developed my content to the point where being able to do this "automagically" would save me perhaps hundreds of repetitive typing hours, not to mention later maintenance. I have looked through some of the past discussions on "self-weaving" here, but didn't find (or maybe don't know enough to recognize) specific examples.

To give a perhaps simpler illustration of what I'm after:

I have a taggly tiddler for a glossary term called [[Curiosity]]. After a bit of text, I'd like a tabset below, containing
1. other glossary terms tagged with [[Curiosity]]
2. other tiddlers (not glossary terms) tagged with [[Curiosity]]
3. a list of tiddlers referencing [[Curiosity]]

The first two use MatchTags, the third uses ShowReferencesPlugin. With the latter, no problem "automating" it, the default argument is "current tiddler" - but with MatchTags, I currently need to manually type in:

<<matchTags " • [[%0]]" "\n" .notTag AND NOT .menu AND Curiosity>>

What I'd like to do is have a variable of some sort substitute "current tiddler" for the text in the last parameter.

Is that possible?

And then ideally put the whole shebang into a ViewTemplate, using either HideWhen or TaggedTemplateTweak

Eric Shulman

unread,
Jun 28, 2011, 4:18:57 AM6/28/11
to TiddlyWiki
> <<matchTags " • [[%0]]" "\n" .notTag AND NOT .menu AND *Curiosity*>>

> What I'd like to do is have a variable of some sort substitute "current
> tiddler" for the text in the last parameter.
> Is that possible?


You should be able to use an "evaluated parameter" for the last value,
where
{{tiddler.title}}
will give you the name of the current tiddler. Thus:
<<matchTags " • [[%0]]" "\n" .notTag AND NOT .menu AND
{{tiddler.title}}>>

However, this *might* not always produce the desired results: for some
uses --
such as transcluding content with the <<tiddler>> macro -- the
'current tiddler' is the one that is being transcluded, rather than
the tiddler in which it is *displayed*. To ensure that the correct
*containing tiddler* is used, a more complex evaluated parameter can
be applied:
{{story.findContainingTiddler(place).getAttribute('tiddler');}}

Note that this code assumes that the macro is being rendered from
within a tiddler displayed in the story column. If you try to use
this evaluated parameter for content rendered in other places (i.e,
the MainMenu, SideBar, or header areas), it will get an error.

Give it a try and let me know how it goes...

-e




>
> And then ideally put the whole shebang into a ViewTemplate, using either HideWhen
> <http://mptw.tiddlyspot.com/#HideWhenPlugin>or TaggedTemplateTweak<http://www.TiddlyTools.com/#TaggedTemplateTweak>

HansBKK

unread,
Jun 29, 2011, 12:03:40 AM6/29/11
to tiddl...@googlegroups.com
Thanks so much for your help Eric, much appreciated

>    {{tiddler.title}}

Works fine, but as you point out, not when the tiddler's transcluded. And unfortunately I'm transcluding all the tiddlers with which I want to do this, so that different nav menu trees (one for each "classification scheme" can include the same standard glossary terms using their different terminology.

So I was heartbroken that the second snippet didn't transclude either

<<matchTags " • [[%0]]" "\n" .tag AND {{story.findContainingTiddler(place).getAttribute('tiddler');}}>>

I'm just hoping maybe there was a small typo there or something, as it also doesn't render when the primary tiddler itself is displayed directly (which is the case in other circumstances, e.g. the user's browsing the glossary tables). I also tried it outside of matchTags:

Keywords related to {{story.findContainingTiddler(place).getAttribute('tiddler');}}:

also no go.

I suppose it's possible that Morris's "TWT-Treeview" design is interfering? I'll get a vanilla TW to test with - also need to get back to testing your AutoTagger's alias feature, as it would be very helpful for my use case if we can get it working.

Keep in mind also that I'm hoping to include this functionality within a ViewTemplate, rather than copying and pasting into each of the 900+ tiddlers - don't know if that makes things easier or completely impossible

If you're ever in Bangkok you've got a free couch and all the Gaeng Kiaow Waan you can eat 8-)


> > And then ideally put the whole shebang into a ViewTemplate, using either HideWhen
> > <http://mptw.tiddlyspot.com/#HideWhenPlugin>or TaggedTemplateTweak<http://www.TiddlyTools.com/#TaggedTemplateTweak>

HansBKK

unread,
Jun 29, 2011, 1:03:47 AM6/29/11
to tiddl...@googlegroups.com
Had a client cancel, so was able to follow up sooner than I thought. Sorry I don't have a place online to upload.

Plain TW + MatchTagsPlugin,

three tiddlers: "Primary" "Tagged" and "Transcluding"

Primary:

Here are tiddlers tagged with this one:
----
<<tag {{tiddler.title}}>>
----
<<tag {{story.findContainingTiddler(place).getAttribute ('tiddler');}}>>
----
<<matchTags " • [[%0]]" "\n" {{tiddler.title}}>>
----
<<matchTags " • [[%0]]" "\n" {{story.findContainingTiddler(place).getAttribute ('tiddler');}}>>


Viewing this works fine in all four cases.

View the transcluding tiddler, the tag macro shows "Transcluding" on both, and the matchTags ones show nothing.

In searching on this "story." string here, I found some examples using ForEach, but at this point I'm thinking a long night of copy-and-pasting might be in the cards 8-(



On Jun 29, 11:03 am, HansBKK <hans...@gmail.com> wrote:
> Thanks so much for your help Eric, much appreciated
>
> >    {{tiddler.title}}
>
> Works fine, but as you point out, not when the tiddler's transcluded. And
> unfortunately I'm transcluding *all* the tiddlers with which I want to do

> this, so that different nav menu trees (one for each "classification scheme"
> can include the same standard glossary terms using their different
> terminology.
>
> So I was heartbroken that the second snippet didn't transclude either
>
> <<matchTags " • [[%0]]" "\n" .tag AND
> {{story.findContainingTiddler(place).getAttribute('tiddler');}}>>
>
> I'm just hoping maybe there was a small typo there or something, as it also
> doesn't render when the primary tiddler itself is displayed directly (which
> is the case in other circumstances, e.g. the user's browsing the glossary
> tables). I also tried it outside of matchTags:
>
> Keywords related to
> {{story.findContainingTiddler(place).getAttribute('tiddler');}}:
>
> also no go.
>
> I suppose it's possible that Morris's "TWT-Treeview<http://twt-treeview-executive.tiddlyspot.com/>"

> design is interfering? I'll get a vanilla TW to test with - also need to get
> back to testing your AutoTagger's alias feature, as it would be very helpful
> for my use case if we can get it working.
>
> Keep in mind also that I'm hoping to include this functionality within a
> ViewTemplate, rather than copying and pasting into each of the 900+ tiddlers
> - don't know if that makes things easier or completely impossible
>
> If you're ever in Bangkok you've got a free couch and all the Gaeng Kiaow
> Waan you can eat 8-)
>
> > > And then ideally put the whole shebang into a ViewTemplate, using either
> HideWhen
> > > <http://mptw.tiddlyspot.com/#HideWhenPlugin>or
>
> TaggedTemplateTweak<http://www.TiddlyTools.com/#TaggedTemplateTweak>
>
> On Jun 28, 3:18 pm, Eric Shulman <elsdes...@gmail.com> wrote:
>
Message has been deleted

HansBKK

unread,
Jun 30, 2011, 2:34:19 AM6/30/11
to tiddl...@googlegroups.com
Sorry to be talking to myself here, but I've arrived at 80% of what I was trying to do and thought I'd follow up.

The only remaining problem is that the listings dynamically generated by macros/plugins in the ViewTemplate don't show through when the tiddler is transcluded - if this is truly unsolvable, then I've come up with workarounds outlined below, that I can live with. However, if there is a way for identical results to be generated at save time (or load time, or with an "update" button, whatever) and then actually stored in the tiddlers so they'll "show through" when transcluded that would be much better for this use case (referenced cross/indexed tiddlers, but rarely updated) - So I'm still looking for suggestions on either strategy from the gurus.

What follows is probably obvious to those guys, but I thought a sketch of my solution so far might be useful for fellow noobs googling in the future, or perhaps stimulate suggestions for something a bit more elegant.

The end result of all this below is that for a given taggly-tiddler "index term" (=keyword), and only for those tiddler types, below a brief description/definition of the term will display a tabbed listing of all content in the TW document tagged with that term, with each tab displaying a different list, "sliced and diced" by Eric's fine MatchTagsPlugin, as well as ShowReferencesPlugin.

Assuming you're starting with a blank vanilla TW, install either HideWhen or TaggedTemplateTweak - I'll use the latter here. This means that any tiddler tagged with ".keyword" will then automagically use the below ".keywordViewTemplate" rather than the default ViewTemplate.

Here's my code for  from my "vanilla testing"

<!--{{{-->
<div class='toolbar' macro='toolbar [[ToolbarCommands::ViewToolbar]]'></div>
<div class='title' macro='view title'></div>
<div class='subtitle'><span macro='view modifier link'></span>, <span macro='view modified date'></span> (<span macro='message views.wikified.createdPrompt'></span> <span macro='view created date'></span>)</div>
<div class='tagged' macro='tags'></div>
<div class='viewer' macro='view text wikified'></div>
 <div macro='tiddler test'></div>
<div class='tagClear'></div>
<!--}}}-->

and from my modified TWT-Treeview "Executive":

<!--{{{-->
<div class='toolbar' macro='toolbar  collapseTiddler collapseOthers fullscreen closeTiddler closeOthers closeAll permalink references jump'></div><br>
</div><div class='title' macro='view title'>Master Quality - </div>
<div><span macro='unsavedChanges panel'></span></div>
<div class='viewer' macro='view text wikified'></div>
<div macro='tiddler .KeywordInclude1'></div>
<div class='tagClear'></div>
<!--}}}-->

Note the inclusion of an external tiddler ".KeywordInclude1". (The fact that I've made it "read only" and put a text warning ahead of the title that it's a "Master" keyword record - not editable here in the child TW, maintained in a "parent glossary/index" TW - isn't relevant for this specific issue - see here for background on that if it's of interest.)

Now that tiddler contains a tabset (very nicely formatted in "Executive" by the way):

<<tabs txtCurrentMode [[• Other Keywords ]] "" [[.K1a]] [[• Not Key Words ]] "" [[.K1b]] [[• Others Tagged ]] "" [[.K1c]]  [[Inbound Links]] "" [[ShowReferences]] >>
----

It used to also contain static text along the lines of "Here are "child" tiddlers tagged with this "taggly" parent one:", but I moved this "upstream" into the static text of the tiddler content so as to provide a self-referential link to the real tiddler accessible from navigational/summary tiddlers that transclude it, since none of the code displayed by the template shows through from there. (One quick question - anyone know how to get the {{tiddler.title}} to display that way - inline in a tiddler rather than inside a macro?)

Then the tiddlers generating the linked list within the tabs:

.K1a : <<matchTags " • [[%0]]" "\n" {{tiddler.title}} AND .keyword>>
.K1b: <<matchTags " • [[%0]]" "\n" {{story.findContainingTiddler(place).getAttribute ('tiddler');}} AND .notKeyword>>
.K1c: <<matchTags " • [[%0]]" "\n" {{tiddler.title}} AND NOT .keyword AND NOT .notKeyword>>

with the fourth tab being automatically generated by ShowReferencesPlugin

Both ".keyword" and ".notKeyword" tiddlers are externally-sourced content tags, the former are the "main" ones, while the latter are synonyms, disambiguation notes etc. used for reference but not actually tagging the primary content in the child TW, which .K1c tab will then display - "all local content tagged with this index term". Note the template could easily be expanded to separate out quotations, summary vs fulltext, statements defining relations between glossary terms, etc.

This core template design is also useful in the "master index" TW, as that third tab will display contain term-specific working notes, to-do lists, journal entries etc pertaining to the indexing project itself, which won't be imported into the children content TWs (not being tagged .keyword or .notKeyword).

Two more questions - have I missed out on any other "self-weaving" aspects that might connect my crosslinked web of index terms - tags and references, any other potential network paths?

And finally, my intention is for every keyword to be "two-way tagged" - in other words, if A tags B then B must tag A - of course that's only within the set of keywords, but they are in a self-contained master TW. Can anyone suggest a way to automate this, or at least help by exposing via lists? I've played with TagGridPluginInfo but have a hard time getting my head wrapped around a way to keep the display manageable with 900+ tagging terms. . .

And PS Eric have I told you how much I love you lately? 8-)

Reply all
Reply to author
Forward
0 new messages