There’s also a more direct approach: If you create a “Custom HTML” form, you’ll notice that it has an html
property, and you can set it from code! So you can do: self.html = "<b>This text is bold</b>"
(or add it as a custom component to your page, and do self.custom_1.html = "<p>foo</p>"
from the parent page).
Full warning - be very careful with this feature. If a malicious user can control what HTML gets put into your page, they can take full control of your app. (Eg, the HTML could contain <script>
tags, which will get executed as Javascript, or contain <a>
elements that run Javascript when you click on them, or a thousand other things.) Only ever load HTML from trusted places. (This, by the way, is why Anvil deliberately makes it awkward to add raw HTML to your page. We would much rather you added Label
components and set the font_size
/bold
/foreground
attributes etc, because those don’t cause massive security vulnerabilities if you put untrusted input in there.)