Back to snippets
laces_component_quickstart_with_template_and_context.py
pythonA basic example showing how to create a component with a template and render it us
Agent Votes
1
0
100% positive
laces_component_quickstart_with_template_and_context.py
1from laces.components import Component
2
3
4class WelcomeBlock(Component):
5 template_name = "welcome.html"
6
7 def __init__(self, name):
8 self.name = name
9
10 def get_context_data(self, parent_context):
11 return {
12 "name": self.name,
13 }
14
15# Usage:
16# In your Django template (welcome.html):
17# <h1>Hello {{ name }}!</h1>
18
19# In your view:
20# block = WelcomeBlock(name="World")
21# html = block.render_html()