How to indent text written in a python block based on the location of "<%" #429
Replies: 1 comment 6 replies
-
the idiomatic way to cancel the extra newline caused by the python block is to use a backslash:
but note that will still render trailing whitespace which you have on the line with the to really not have the whitespace render without applying post-processing, you have to not put it in the template in the first place, like this:
I would need to see an example how this function is intended to be used, it sounds like it requires programmatic use of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have the following template content:
"some python code" will add some lines between the 2 "some text" and the content of these lines must be indented like both "some text".
So, what I did is to consider the location of "<%" as the reference for all the text written by "some python code".
To achieve that, I created the following function:
which provides the indentation of "<%" not in the template but in the text that has been processed up to the "<%".
Then I can prefix each "context.write()" (except the first one which is already indented correctly) with the indentation string returned by the function "GetIndent()".
The problem of this function is that it uses internal data of mako class.
So I open this discussion in case this could interest enough users of mako to eventually provide this as a feature of mako.
Or maybe there are better ways to achieve this goal.
Thank you
Ronan
Beta Was this translation helpful? Give feedback.
All reactions