Created
September 8, 2024 17:13
-
-
Save pauleveritt/278a93ff441dcd8b68c7e51774cf16bc to your computer and use it in GitHub Desktop.
Nested template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We've generally thought of nesting being an interpolation | |
# that called the html "tag function" (now template function) | |
def Sidebar(heading: str, items: list[Any]) -> HTMLTemplate: | |
return t""" | |
<aside> | |
<h1>{heading}</h1> | |
<ul> | |
{html(t"<li>{item}</li>" for item in items}")} | |
</ul> | |
</aside> | |
""" | |
# But does it need to do the HTML conversion inside | |
# the template? Could it instead just nest a template, | |
# and the outermost `html()` would process it? | |
# | |
# A good bit nicer than having an extra html(). But | |
# do we think the DSL info in the typing would extend | |
# to nested templates? | |
def Sidebar(heading: str, items: list[Any]) -> HTMLTemplate: | |
return t""" | |
<aside> | |
<h1>{heading}</h1> | |
<ul> | |
{t"<li>{item}</li>" for item in items}"} | |
</ul> | |
</aside> | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment