tags: $:/tags/ViewTemplate
text:
<$list filter="[all[current]tag[Foo]]">
...
tags: $:/tags/ViewTemplate
text:
<$list filter="[all[current]tag[Foo]]">
...Such "conditional viewtemplates" are cool but I have a feeling they can be very inefficient in that such custom templates often only get positive hits for very few tiddlers. (Is my reasoning flawed?)
Is there instead a targeted way to control which viewtemplates the current tiddler shows?For example, is there some pragma that, for current, can command "show fields a and b but not the text field nor the tags"?
<$list filter="[all[shadows+tiddlers]tag[$:/tags/ViewTemplate]!has[draft.of]]" variable="listItem">
<$transclude tiddler=<<listItem>>/>
</$list>tag[$:/tags/ViewTemplate] to eg: tag[$:/tags/myTemplate] based on a tiddler field, it should work "out of the box". ... Maybe ;)I'm not sure, if I understand the question right. .. It will always hit for tiddlers tagged: Foo in your example.
Showing a different ViewTemplate could be done by using a new field. BUT .. It would need new core code to support it.
It's $:/core/ui/ViewTemplate that would need to be changed. The list there looks like this:<$list filter="[all[shadows+tiddlers]tag[$:/tags/ViewTemplate]!has[draft.of]]" variable="listItem">
<$transclude tiddler=<<listItem>>/>
</$list>
If we change a part from the filter fromtag[$:/tags/ViewTemplate]to eg: tag[$:/tags/myTemplate] based on a tiddler field, it should work "out of the box". ... Maybe ;)
\define folded-state()$:/state/folded/$(currentTiddler)$\end<$vars storyTiddler=<<currentTiddler>> tiddlerInfoState=<<qualify "$:/state/popup/tiddler-info">>><div data-tiddler-title=<<currentTiddler>> data-tags={{!!tags}} class={{{ tc-tiddler-frame tc-tiddler-view-frame [<currentTiddler>is[tiddler]then[tc-tiddler-exists]] [<currentTiddler>is[missing]!is[shadow]then[tc-tiddler-missing]] [<currentTiddler>is[shadow]then[tc-tiddler-exists tc-tiddler-shadow]] [<currentTiddler>is[system]then[tc-tiddler-system]] [{!!class}] [<currentTiddler>tags[]encodeuricomponent[]addprefix[tc-tagged-]] +[join[ ]] }}}><$set name="_viewtemplate-tag" filter="[all[current]get[sq-viewtemplate]else[$:/tags/ViewTemplate]]"><$list filter="[all[shadows+tiddlers]tag<_viewtemplate-tag>!has[draft.of]] [enlist{!sq-viewtemplate-add}] -[enlist{!!sq-viewtemplate-remove}]" variable="listItem"> <$transclude tiddler=<<listItem>>/></$list></$set></div></$vars>
In one published wiki for a client I have a view template whose first test is does the current tiddler have an object-type field. It then uses the value to load the view template for that object type. I see no performance problems.
In each of my object view templates I refer to field values through a macro '<<field fieldname>>' which looks up how to display the fieldname according to a field definition and its field type e.g. date, and In fact displays the fields according to a global or local tiddler mode read-only view update and edit.
This allows the same object template to be used for all modes.
In this case most tiddlers with an object type have all there values in fields other than text which is reserved for simple notes.
In addition I have a global designer mode that if on the view template will show a link to the object template. And a field mode that places a link to the fields definition and field-type just after it is displayed.
There happens to be less field types than field definitions.
This is a potted overview but I hope it shows a little structured design can go a long way and without performance problems.
Perhaps one day I will publish this as a tiddlywiki platform tool.
Regards
Tony
Saq - thanks a lot for that code!A variant of your code would be to allow for sq-viewtemplate to contain a filter rather than a tag, so the user has the option to directly specify titles and/or [tag[]] including tag[$:/tags/ViewTemplate] if one merely wants to add/remove to the standard set. This would also make it easier to add a template into the correct position.