Change text of filtered tiddlers

I want to prepend {{||ContactInformation}} to all ‘[tag[Contact]]’ tiddlers. I read about this and tried the following code:

<$button>
<$action-setfield $tiddler="[tag[Contact]]" text="{{||ContactInformation}}"/>
<$action-navigate $to="$:/ControlPanel"/>
Go to Control Panel "Appearance" tab
</$button>

But that does not work. So I added the <$list> widget like so:

<$button>
<$list filter="[tag]Contact]]">
<$action-setfield $tiddler=<currentTiddler> text="{{||ContactInformation}}"/>
</$list>
<$action-navigate $to="$:/ControlPanel"/>
Go to Control Panel "Appearance" tab
</$button>

But that did not work, either.

Moreover, even if it did, it would replace the contents of the text field, I want to prepend the field.

How do I do what I want to do?

<$button>
<$list filter="[tag]Contact]]">
<$action-setfield $tiddler=<currentTiddler> text="{{||ContactInformation}}"/>
</$list>
<$action-navigate $to="$:/ControlPanel"/>
Go to Control Panel "Appearance" tab
</$button>
  • You have a syntax error in the filter:
    <$list filter="[tag]Contact]]"> should be <$list filter="[tag[Contact]]">

  • and another syntax error in the <$action-setfield>:
    tiddler=<currentTiddler> should be tiddler=<<currentTiddler>>

  • To prepend content, try this:

<$button> add contact info to "contact" tiddlers
<$list filter="[tag[Contact]]">
<$vars oldtext={{{ [<currentTiddler>get[text]] }}} newtext="{{||ContactInformation}}

">
<$action-setfield $tiddler=<<currentTiddler>> text={{{ [<newtext>addsuffix<oldtext>] }}}/>
</$vars>
</$list>
</$button>
  • oldtext=... fetches the current contents of the target tiddler
  • newtext=... defines the stuff to add
  • Note the blank line at the end of the definition of “newtext”… this is important, since you want to make sure that a blank line is added between the newtext and the oldtext in order to preserve any “block mode” formatting of the oldtext (e.g., if the old text started with a bullet item, etc.)
2 Likes

If you want a solution without having to hard code {{||ContactInformation}} to every contact tiddler, you can use viewtemplate. Create a tiddler with the following content:

<$list filter="[all[current]tag[Contact]]">

{{||ContactInformation}}
</$list>

Tag it with $:/tags/ViewTemplate. Then click on this tag and reorder the above tiddler to where you want it to be (e.g. before body).

But if you want the actual code {{||ContactInformation}} to be inside the text field of every contact tiddler then I have no idea…

2 Likes

Pak’s response is the correct “TiddlyWiki Way” to do this.

Using a ViewTemplate automatically shows the ContactInformation in every tiddler tagged with “Contact”… and, when you create new “Contact” tiddlers, they will also automatically show their ContactInformation as well, without having to remember to add the syntax to those new tiddlers.

Also, my solution, while it addresses your specific question, is somewhat problematic… each time you press the button, it will add the {{||ContactInformation}} syntax to every “Contact” tiddler, even those tiddlers for which the syntax has already been added.

-e

3 Likes

@EricShulman Thanks. After your comments about the correct TiddlyWiki way, I will use that method. But this explains a lot of other things.

@Pak Thanks. This works perfectly except that the text size of the text produced by view template appears to be smaller than that of the text produced directly or by transclusion as template.

So, a heading two line coming from the view template appears to be smaller in size than a heading two line in the body.

What could be the reason behind this? How to fix this?