akonsu
akonsu

Reputation: 29566

Display Text in Template?

I have a text field in my model that contains markdown text. I need to convert the text to html and show it in my .pt template. what is the best way to do it?

I realise that I can add a method to my model that converts the field and returns HTML, and then call the method from my template, but can I do it without this extra method, by using only the markdown field in my template similarly to Django's?

{{ mytext|markdown:"safe" }}

Upvotes: 1

Views: 381

Answers (1)

Ross Patterson
Ross Patterson

Reputation: 5742

Plone, which uses TAL for it's templating engine and can use StructuredText, reStructuredText, and other rich text formats, does all the rendering to HTML outside TAL. So you might be barking up the wrong tree in the approach you're going for.

That said, TAL has a somewhat extensible "expression" system which is why you can have path expressions (the default) or python expressions. In the zope world, which includes plone, there's a page composition system called content providers, so someone implemented a provider tal expression. So maybe you can look at that:

tales.py

configure.zcml

The structure keyword is still your easiest bet.

<div tal:replace="structure view/getMarkdown">rendered markdown</div> 

But structure is a special case keyword and not an extensible part of page templates.

Upvotes: 1

Related Questions