Skip to content

How to output HTML from a function in a template #3

Answered by gi0baro
denesl asked this question in Q&A
Discussion options

You must be logged in to vote

@denesl Renoir uses an __html__ method on objects for escaping when available. You can mimic what Emmett does building a wrapper class:

class asis:
    def __init__(self, val):
        self.val = val

    def __html__(self):
        return str(self.val)

the you function just have to return the wrapped content

def f():
    ...
    return asis(whatever)

or you can add you class in Renoir's context and call-it directly from the template:

{{ =asis(f()) }}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@denesl
Comment options

Answer selected by denesl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2 on October 27, 2021 07:59.