Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic components #98

Open
pietz opened this issue Oct 12, 2024 · 2 comments
Open

Dynamic components #98

pietz opened this issue Oct 12, 2024 · 2 comments

Comments

@pietz
Copy link

pietz commented Oct 12, 2024

Sadly something like this doesn't seem to work:

{#def sections #}
<div id="main">
    {% for section in sections %}
        <{{ section }} />
    {% endfor %}
</div>

Any workarounds or ideas?

@jacobcheatley
Copy link
Contributor

Possible workaround - does the {{ content }} special variable work for your use case?

e.g.

// Layout.jinja
<!doctype html>
<div id="main">
  {{ content }}
</div>

and

// TestPage.jinja
<Layout>
    <SomeSection />
    <SomeOtherSection />
    <div>Extra content</div>
</Layout>

Alternatively If you need to do something server side to decide which sections to render - maybe render the html to string for those sections with one call, and pass that as the content (or some other argument) to the rendering of the Layout template?

@jpsca
Copy link
Owner

jpsca commented Oct 20, 2024

If I understand it correctly, sections is a list of component names, isn't it?

You can render a component by name using catalog.irender like this:

{#def sections #}
<div id="main">
    {% for section in sections %}
        {{ catalog.irender(section) }} 
    {% endfor %}
</div>

Let me know if that's what you want it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants