How can I replace the default text body with the name and value of a custom field in a tiddler?

I’m creating some tiddlers with specific fields depending on the tags.

I create a tiddler to visualize them in the new tiddler. The thing is that they are shown at the bottom of the tiddler, but i would like that they will replace the default text body. This is my code:


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

  <div class="tw-costs-fields" style="margin-top: 1em; padding: 0.5em; border-top: 1px solid #ccc;">

    <p><strong>Concerned Domain:</strong> <$view field="concernedDomain"/></p>

  </div>

</$list>

I am trying with another class “tc-edit-texteditor” but it doesn’t work.

Do you know if there is another class or another way thta it help me to modify the default text body?
Thanks in advance!
Rosi

Hello @Rosi
I may be missing something here, but have you tagged your tiddler with
$:/tags/ViewTemplate

If you want to replace the default text body, you should use viewtemplate body cascade

https://tiddlywiki.com/prerelease/#View%20Template%20Body%20Cascade

You can do this with a cascade, specifically the View Template Body Cascade. Adding to this generally takes two tiddlers. The first one has the tag $:/tags/ViewTemplateBodyFilter and is a filter expression that will return the title of the second one if your condition is met (here, if it has the tag Issues.) It could look something like this:

title: $:/_/my/config/ViewTemplateBodyFilters/issues
tags: $:/tags/ViewTemplateBodyFilter
list-before: $:/config/ViewTemplateBodyFilters/default

[tag[Issues]then[$:/_/my/core/ui/ViewTemplate/body/issues]]

The list-before fields ensures that this is displayed before the default view (which formats your text field.) You could alternately do this by dragging and dropping the element on the tag pill for $:/tags/ViewTemplateBodyFilter, but putting it here makes it easier to share.

The second one has the content you will want to show:

title: $:/_/my/core/ui/ViewTemplate/body/issues

<div class="tw-costs-fields" style="margin-top: 1em; padding: 0.5em; border-top: 1px solid #ccc;">
  <p><strong>Concerned Domain:</strong> <$view field="concernedDomain"/></p>
</div>

(You can make these titles anything you want. I tend to use a system namespace starting with _ for easy fidability.)

Now a tiddler that looks like this:

title: Issues Tiddler 1
tags: Issues
concernedDomain: some important domain

Text content will be ignored

Will show up like this:

image

If you remove the Issues tag, the text content is restored:

image

If you also want to include the text content, but hide it under a details element, you could transclude the default template by adding something like this to the template tiddler:

<details>
  <summary>Main Content</summary>
  <$transclude $tiddler="$:/core/ui/ViewTemplate/body/default" />
</details>

You can test this by downloading the following and dragging the resulting file onto a wiki:

IssuesTemplate.json (799 Bytes)

2 Likes

Thank you @Scott_Sauyet for the detailed example and explanation and @arunnbabu81 for the link to viewtemplate body cascade
I must read more …

I am curious about your workflow, though I didn’t want to clutter up the technical explanation above with such musings.

Why do you want to hide the main content in this case? Is the idea that anything tagged Issue must be dealt with before working with the content, that this tag should be transient? Do you expect to be able to resolve such issues relatively soon?

If not, I might just make this a ViewTemplate but sort it above the main body content, using the same list-before or drag-and-drop as above.

I use ViewTemplates all the time. They are very useful. I’ve only used the ViewTemplateBodyCascade in a very few places, and usually I do as my final note above suggested, and simply transclude the default view in another manner in my own version.

My response was simply to offer an example, not knowing what other text would be included in the tiddler or if it was tagged as a ViewTemplate or not.
I wouldn’t want to hide the content.

workflow ? not sure what you really mean, that would suggest some organisation on my part :grinning:.

Unlike many TW users on this forum, I generally tend to potter around and try to learn things (Buttons, Templates, Edit-Text fields, lookups re; your forms ) that I can use for things like Booklists, Music, DVD’s Recipes ToDo Lists with the hope that one day I can put it all together in a wiki of some sort, although I have several single file wiki’s.

I use ViewTemplates all the time. They are very useful.

Generally I would use a viewtemplate (say a Recipe) and add detail elements (ingredient selection) and text (cooking method and additional notes) accordingly, not hiding the main content but transcuding the specific fields.

When and If I can identify a main use for a wiki, I can then hopefully apply the little knowledge I have to build a useful tool.

Indeed. That post is the best, most succinct (dare I say “missing manual”) coverage of Template Cascades I’ve seen. Exemplary – and bravo, sir. :clap: Consider yourself bookmarked. :bookmark:

Hi Sunny! Yes, I did. that code works perfectly tagging the tiddler with
‘’’ $:/tags/ViewTemplate ‘’’

Oops, sorry, I thought I was responding to the OP. I found the whole “hide the main text and show something entirely different if it has the Issues tag” slightly odd, and was wondering what it was for.

Uaaooo! Thanks so much @Scott_Sauyet
It works perfectly…i will check the details on Monday.
Have a nice weekend!
Rosi

Hi @Scott_Sauyet
regarding viewtemplate body cascade, I like this example for recipe tiddlers.
$__config_ViewTemplateBodyFilters_recipe.json (242 Bytes)
$__ui_ViewTemplate_body_recipe.json (261 Bytes)
Chicken Noodle Soup.json (1011 Bytes)

I think it could be used in a number of ways

Some days ago, I did create a step by step write up, discussing different possibilities how to manipulate the view-template body of a tiddler, in the Tips & Tricks category.

1 Like

Thanks for the reminder @pmario