Line Breaking In Chameleon
I have used the pyramid framework to build a large web application. Among other things, this application allows the user to enter text into a text area form field. This text is th
Solution 1:
You need to break the text into separate lines, then render this using a loop and <br/>
tags:
<span tal:omit-tag=""
tal:repeat="line text_with_newlines.splitlines()">
${line}<br />
</span>
This uses the str.splitlines()
method to split the text on newlines, then the loop adds a <br />
break tag after each line of the text.
You are quite right not doing this in the view, then forcing Chameleon to accept your inserted <br />
tags by setting the structure:
flag. Luckily there is absolutely no need for that anyway.
Solution 2:
Another possibility is to do something like the following:
import webhelpers.html.tags as t
s = t.literal(t.BR).join(s.split(t.NL))
You can of course create a helper function from it.
Post a Comment for "Line Breaking In Chameleon"