Is it possible to get the rendered body content from within a Mako template? What I mean is that I can display the body using ${self.body()}
, but what if I want to do something to it first?
Asked
Active
Viewed 422 times
2

Brendan Long
- 53,280
- 21
- 146
- 188
2 Answers
4
Apparently what I was looking for is the capture
function. From the docs:
The other way to buffer the output of a def or any Mako callable is by using the built-in capture function. This function performs an operation similar to the above buffering operation except it is specified by the caller.
${" results " + capture(somedef) + " more results "}
Or in my case:
<%
body = capture(self.body)
# etc.
%>

Brendan Long
- 53,280
- 21
- 146
- 188
1
One approach would be to pass it through a custom defined filter
<%
def myFilter(txt):
return "whatever I want to do it"
>%
${self.body() | myFilter}

donkopotamus
- 22,114
- 2
- 48
- 60