Transcluding through templates to preserve line breaks

117 views
Skip to first unread message

Paul Lee

unread,
Dec 3, 2019, 12:55:06 PM12/3/19
to tiddl...@googlegroups.com
I use the <$transclude> widget to use some tiddlers as data sources for the content rendered in other tiddlers. I need to have the line breaks and white space from the data tiddler preserved. Currently, the text from the data tiddler is displayed, but all the paragraphs are run together.

I think what I need to do is use a template attribute in the widget, in order to render the  content from the data tiddler through some code that will force the preservation of the original line breaks. I experimented using some of the default templates, such as $:/core/ui/ViewTemplate/body, adding those into the widget has no effect. I don't know how to go about creating a template to preserve line breaks.

<$list filter="[all[current]has[content-tiddler]]">
<$transclude tiddler={{!!content-tiddler}} template="$:/core/ui/ViewTemplate/body" />
</$list>


What I primarily want to do is to preserve the line breaks as they exist in the tiddler referenced in the content-tiddler field, which gets output by this method (compliments to Mark S.). Should I isntead look at manually inserting a new paragraph after every paragraph using some advanced filter notation?

Or is there a way to do this with a template?

PMario

unread,
Dec 3, 2019, 1:13:30 PM12/3/19
to TiddlyWiki
Hi Paul,

The "How to apply custom styles" tiddler of the docs may be interesting.

-mario

Eric Shulman

unread,
Dec 3, 2019, 1:15:12 PM12/3/19
to TiddlyWiki
On Tuesday, December 3, 2019 at 9:55:06 AM UTC-8, Paul Lee wrote:
I use the <$transclude> widget to use some tiddlers as data sources for the content rendered in other tiddlers. I need to have the line breaks and white space from the data tiddler preserved. Currently, the text from the data tiddler is displayed, but all the paragraphs are run together.

Have you tried using the mode="block" parameter of the $transclude widget?


Alternatively, if you surround the $transclude with <pre>...</pre>, that should also preserve the line breaks and whitespace.

enjoy,
-e

Paul Lee

unread,
Dec 3, 2019, 2:44:58 PM12/3/19
to TiddlyWiki

Have you tried using the mode="block" parameter of the $transclude widget?
I hadn't. That's an ideal solution. It works as expected.
 


Alternatively, if you surround the $transclude with <pre>...</pre>, that should also preserve the line breaks and whitespace.


Yes, I was just about to post a reply stating that surrounding the contents of the data tiddler with """ also preserves the line breaks. Likely this is equivalent to the <pre></pre> markup.

Thanks very much! :)
Reply all
Reply to author
Forward
0 new messages