Storing formatted text but not in the text field

I have been researching how I can store formatted text, using wiki formatting characters, in a field but not the text field. On display, the wiki formatting should be observed so the user sees what they might see in a formatted text field.

From what I can read, JSON seems the way to go.

Can someone point me into the right direction please.

bobj

I think its a bit of a journey, and there are different ways to go about it depending on what you want to achieve… but to start on one right direction you could:

  1. Clone a copy of $:/core/ui/ViewTemplate/body/default - this is the template for what you see as formatted text. You will need to edit this to show your new text field.
  2. Tag that cloned copy with the system tag $:/tags/ViewTemplate so that it will show up on every tiddler.

Once you get this far you’ll notice that most tiddlers will repeat the formatting of the text field and that some tiddlers have red boxes of errors (from too much recursive transclusion)… To fix this you can edit your cloned viewtemplate to be more selective - say to only transclude the field text-2 if it exists. (use the conditional formatting <%if etc… )

The editing of this field can be done in a similar way with a clone of $:/core/ui/EditTemplate/body/editor and system tag $:/tags/EditTemplate… but after that it gets a bit more complex in terms of things like - reusing the toolbar if desired, positioning this above the fields, making the text-2 field not visible among the fields list …

I would recommend creating a new wiki for this before starting - customising at this level can be precarious.

:smiley:

You may have a look at the linked thread, which describes my Field Editor Plugin. It also contains a link to a Youtube video, which shows the functionality.

It is not a 100% fit to the questions in the OP, since there is no field-editor - preview. The formatted output can only be seen once saved and when the fields are rendered by a view-template

2 Likes

Thats a much nicer solution for the editing of the fields… well done !

Could you then combine that with the cloneing of the View template body to show both fields in view mode ?

@Christian_Byron – I did move the answer to your question into it’s own Tips & Tricks post.

It starts with simple examples and gets more and more complex, but also powerful.

HowTo: Use Custom and Complex ViewTemplates (Tagging and Cascade)

It you use the edit-text widget to edit a multi-line field its is easy to create them, the problem is however if you attempt to edit that field with the default field editor, you see in edit mode, It will destroy the line feeds and save it back as a single line field.

  • We now have the “Field Edit” cascade, we need to set up one to provide an alternate editor for named multi-line fields, I have done this for a local view template that is only displayed on the current tiddler, we also have to stop the default field editor operating on the new field.
    • Its possible to use the new field mechanisium to create such a field but you need to imediatly switch to the multi-line editor.
  • There may be a few other complications to resolve such as when importing/exporting tiddlers with such a field, or saving to the server, but I sure most of these can be resolved.

I can provide my example and more info if required.

Once you have such a field if you want the content wikified, rendered as wikitext etc… you will need to intentionally display it in a way that renders it like the text field is.

There is an important difference between single line field values and multi-line field values. If you ever store them as single tiddlers using a client / server configuration, they will be saved as .JSON and .META files.

At the moment, they can not be converted back to .TID files. So you should be really sure, that you want to use multi-line fields.

@pmario but do they still continue to work as tiddlers in the interactive wiki? I imagine they do.

I can test tomorrow with my local view template on top of a node wiki, where I add an additional multiple line field to tiddlers.

Sure. They are “standard” tiddlers in the browser. We do not have .TID files, which can handle multi-line fields at the moment.

I just tested my local view template tool, and as soon as I introduce a second line to the extra multi-line field to a tiddler if now saves the tiddler as a JSON.

Now keep in mind this is totally automatic and can only impact a process that makes an assumption the tiddler on disk is a .tid file. Otherwise it can now be found as a .json and the interactive wiki works as usual.

If you install Local-Viewtemplate.json (4.5 KB) then in any tiddler add a local-viewtemplate field in the editor the new, additional, multi-line field editor becomes visible. If you look in the package all the information is available how to replicate this.

  • This package helps designing because you can test how a view template tiddler will look, but only on the current tiddler.
  • It is an example of an additional multi-line text field.

tid form

created: 20250713230557683
modified: 20250713230647727
object-type: todo
tags: Inbox todo
title: target.tiddler
type: text/vnd.tiddlywiki

Tiddler to include multi-line content

JSON form once added local-viewtemplate field but only once \n implied.

[
    {
        "created": "20250713230557683",
        "text": "Tiddler to include multi-line content",
        "tags": "Inbox todo",
        "title": "target.tiddler",
        "modified": "20250713231438862",
        "type": "text/vnd.tiddlywiki",
        "object-type": "todo",
        "local-viewtemplate": "!Local view Template\n* new item"
    }
]