Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Template tagin määritys:
- @register.tag()
- def hieno_tagi(parser, token):
- return multipart_tag(
- parser=parser,
- token=token,
- end_tag_name='endhieno_tagi',
- template_name='template_tags/hieno_tagi.html',
- parameters={'name': 'Nobody', 'is_authenticated': False},
- sub_tags={'href': None, 'class_name': 'btn btn-danger'},
- )
- # template_tags/hieno_tagi.html:
- """
- <div class="hienon-tagin-template">
- <a {% if sub_tags.href is not None %}href="{{sub_tags.href}}"{% endif %} class="{{sub_tags.class_name}}">
- {{content}}
- </a>
- </div>
- """
- # Käyttö:
- """
- {% hieno_tagi name='Matti' is_authenticated=request.user.is_authenticated %}
- Lähetä
- {% href %}
- {% url 'general:index' %}?get_parametri=1
- {% class_name %}
- btn btn-primary
- {% endhieno_tagi %}
- """
- # Lopputulos:
- """
- <div class="hienon-tagin-template">
- <a href="/main/index?get_parametri=1" class="btn btn-primary">
- Lähetä
- </a>
- </div>
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement