Advertisement
Janne252

Untitled

Feb 6th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1.  
  2. # Template tagin määritys:
  3. @register.tag()
  4. def hieno_tagi(parser, token):
  5.     return multipart_tag(
  6.         parser=parser,
  7.         token=token,
  8.         end_tag_name='endhieno_tagi',
  9.         template_name='template_tags/hieno_tagi.html',
  10.         parameters={'name': 'Nobody', 'is_authenticated': False},
  11.         sub_tags={'href': None, 'class_name': 'btn btn-danger'},
  12.     )
  13.  
  14. # template_tags/hieno_tagi.html:
  15. """
  16. <div class="hienon-tagin-template">
  17.     <a {% if sub_tags.href is not None %}href="{{sub_tags.href}}"{% endif %} class="{{sub_tags.class_name}}">
  18.         {{content}}
  19.    </a>
  20. </div>
  21. """
  22.  
  23. # Käyttö:
  24. """
  25. {% hieno_tagi name='Matti' is_authenticated=request.user.is_authenticated %}
  26.     Lähetä
  27. {% href %}
  28.    {% url 'general:index' %}?get_parametri=1
  29. {% class_name %}
  30.     btn btn-primary
  31. {% endhieno_tagi %}
  32.  
  33. """
  34.  
  35. # Lopputulos:
  36. """
  37. <div class="hienon-tagin-template">
  38.    <a href="/main/index?get_parametri=1" class="btn btn-primary">
  39.        Lähetä
  40.    </a>
  41. </div>
  42. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement