How to create component "presets"? #136
-
{% {% if url %} {% endwith %} Is giving me "Did you forget to load/register this 'endwith' tag" error |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Ah, I see that I should use c-vars instead of with. But when I have c-vars inside my cotton/button.html, I get a TemplateDoesNotExist at cotton/vars.html |
Beta Was this translation helpful? Give feedback.
-
This does rely on you adding an item getter templatetag to get an item from a dict by its key. So putting this in a templatetag file and loading it: @register.filter
def get_item(dictionary, key):
return dictionary.get(key) (an upcoming cotton version will have this baked in) And then you can do: <!-- button.html -->
<c-vars
style="default"
:styles="{
'default': '...',
'primary': '...',
'secondary': '...',
}"
/>
<button class="{{ styles|get_item:style }}">hello</button> <!-- view.html -->
<c-button />
<c-button style="primary" />
<c-button style="secondary" />
|
Beta Was this translation helpful? Give feedback.
-
Aha! I have to create the vars.html file too! |
Beta Was this translation helpful? Give feedback.
@iamalexpayne
with
style=styles=(common_styles|add:primary_styles if style == 'primary' else common_styles|add:secondary_styles)
are you sure this is working code even without cotton?<c-vars />
, and something like this may help you:This does rely on you adding an item getter templatetag to get an item from a dict by its key.
So putting this in a templatetag file and loading it:
(an upcoming cotton version will have this baked in)
And then you can do:
<!-- button.ht…