Render a custom type as text/plain

45 views
Skip to first unread message

Gabriel Montagné Láscaris-Comneno

unread,
Apr 1, 2023, 11:41:13 AM4/1/23
to TiddlyWiki
Hi,

I registered a new type on my TW,  `text/x-fountain`, as per https://groups.google.com/g/tiddlywiki/c/l_uxgh_tsDU.  All good; it shows up on the type selector.

But I'd like it rendered as if it was a `text/plain` file, not as a TW 5 tiddler.

Is there a simple way to achieve this?

Thanks,
Gabriel

Eric Shulman

unread,
Apr 1, 2023, 12:27:21 PM4/1/23
to TiddlyWiki
You want to use the TWCore's "cascade" mechanism (see https://tiddlywiki.com/#Cascades)

* Create a tiddler (e.g., "$:/config/ViewTemplateBodyFilters/x-fountain"), containing:
   [type[text/x-fountain]then[$:/core/ui/ViewTemplate/body/rendered-plain-text]]
* Tag it with `$:/tags/ViewTemplateBodyFilter`
* Add a field named `list-before` with no field value

Notes:
* Your "cascade" tiddler can have any name.  The name suggested above is consistent with the existing TWCore "ViewTemplateBodyFilters" shadow definitions.
* The tiddler content is evaluated by the TWCore cascade mechanism, and basically says: "If the tiddler's type field is equal to "text/x-fountain", then display the tiddlers body using the "$:/core/ui/ViewTemplate/body/rendered-plain-text" template
* The `$:/tags/ViewTemplateBodyFilter` tag adds your definition to the default ViewTemplateBodyFilters cascade
* The `list-before` field ensures that your custom cascade is evaluated first when the cascade is processed by the TWCore

enjoy,
-e

P.S. You might want to visit https://talk.tiddlywiki.org/, which is a "Discourse" server that is now the TiddlyWiki community's primary discussion/Q+A area.

Eric Shulman

unread,
Apr 1, 2023, 12:35:04 PM4/1/23
to TiddlyWiki
Addendum:

Instead of
[type[text/x-fountain]then[$:/core/ui/ViewTemplate/body/rendered-plain-text]]

your cascade definition should be:
[type[text/x-fountain]then[$:/core/ui/ViewTemplate/body/code]]

The difference is that the first definition will render embedded wikitext syntax,
while the second definition simply displays the content as plain text without any other processing.

-e

Gabriel Montagné Láscaris-Comneno

unread,
Apr 1, 2023, 2:02:29 PM4/1/23
to TiddlyWiki
Amazing Eric!  Worked perfectly.  And thanks for the link and explanation!   I'll use the Discourse server for these type of questions going forward.
Again, 1000 thanks!
Cheers,
Gabriel

Gabriel Montagné Láscaris-Comneno

unread,
Apr 1, 2023, 2:08:53 PM4/1/23
to TiddlyWiki
Interestingly, when I transclude the node, it's still rendered as a wiki tiddler, not as code.  I wonder, Eric, if, from the top of your head, you'd know how to work around that?
Thanks again, Gabriel

Eric Shulman

unread,
Apr 1, 2023, 2:29:50 PM4/1/23
to TiddlyWiki
Instead of using simple transclusion (i.e., `{{TiddlerTitle}}`) use the `$codeblock` widget, like this:
`<$codeblock code={{TiddlerTitle}}/>`

Gabriel Montagné Láscaris-Comneno

unread,
Apr 1, 2023, 2:35:59 PM4/1/23
to TiddlyWiki
Wonderful :-) Thanks a lot!

Gabriel Montagné Láscaris-Comneno

unread,
Apr 1, 2023, 4:29:15 PM4/1/23
to TiddlyWiki
The editor preview is also rendering it as a wiki tiddler, not as code.  I can live with that, but I was hoping there'd be a fundamental "and here is how you render this type of tiddler" way.
Still,  it's incredible how flexible TW is!

Cheers,
Gabriel

springer

unread,
Apr 1, 2023, 11:05:26 PM4/1/23
to TiddlyWiki
I bet it's possible to have the preview pane give you a preview according to the template you need.

I've just discovered that I can get such an effect within dynamic tables (which can toggle their expanded rows into edit mode). See this thread: https://talk.tiddlywiki.org/t/hacking-tbl-expand-with-templates-in-shiraz-dynamic-tables/5824/7

I suspect part of the explanation has to do with how the preview pane works for "draft of" tiddlers, if/when you haven't specified a different Edit template (via the cascade for edit mode)

There are various plugins that offer editing interfaces that edit without setting up a "draft of" tiddler, and these may help you (or anyone working regularly with templates other than the default one) to see a live preview of your edits in progress as they would appear in their "final" form. 

(Then again, if you're looking for a completely non-wikified mode, is the preview pane doing anything useful for you at all? Wouldn't you just toggle that preview pane off for these tiddlers?)

springer

unread,
Apr 1, 2023, 11:50:41 PM4/1/23
to TiddlyWiki
Just a quick follow-up: My memory was wrong -- I'm actually seeing the preview pane applying alternate view templates correctly in nearly all cases. The exceptions all turned out to involve cascade-conditions that referenced things like how the title begins (which are of course disrupted by "Draft of..." prefix). 

So, I'm baffled as to why the template specified in your ViewTemplate cascade is not working properly in the preview pane while editing.

Gabriel Montagné Láscaris-Comneno

unread,
Apr 2, 2023, 4:48:44 PM4/2/23
to TiddlyWiki
Yes, very strange.  I tried it out with a fresh wiki to see if I had something interfering, but I got the same result.  Thanks for chipping in : )
Reply all
Reply to author
Forward
0 new messages