Login

Tag "templatetags"

Snippet List

Read image url as base64

Read the image url as base64 in django, this snippet usefull if you using the `django-easy-pdf` to solve this issue https://github.com/nigma/django-easy-pdf/issues/53 Usage example: ``` <img src="{{ profile.photo.url|read_image_as_base64 }}"> ```

  • django
  • image
  • templatetags
  • base64
  • imagepreview
Read More

tweetparser filter

Django Template Filter that parse a tweet in plain text and turn it with working Urls Ceck it on [GitHub](https://github.com/VincentLoy/tweetparser-django-template-filter) # tweetParser Django Template Filter this is a port of [tweetParser.js](https://github.com/VincentLoy/tweetParser.js) to work as a Django template filter ## How does it work ? Once installed, just : ``` <p>{{ your_tweet|tweetparser }}</p> ``` ## Installation Take a look at the [Django Documentation](https://docs.djangoproject.com/en/1.8/howto/custom-template-tags/) #### You can change the classes given to each anchor tags ``` USER_CLASS = 'tweet_user' URL_CLASS = 'tweet_url' HASHTAG_CLASS = 'hashtag' ```

  • filter
  • templatetag
  • templatetags
  • twitter
  • parse
  • parser
  • tweet
Read More

yandex maps templatetag

https://github.com/coolchevy/django-yandexmaps django-yandexmaps ================= easy maps integration via yandex maps api Installation ============ 1. Add your YANDEXMAPS_API_KEY to settings.py http://api.yandex.ru/maps/form.xml/ 2. Add 'yandex_maps' in INSTALLED_APPS Usage ============ Template:: {% load yandexmaps_tags %} {% yandex_map_by_address object.get_address object.title 500,300 %} Demo ============ http://colorsound.com.ua/clubs/porter-pub-1/

  • template
  • django
  • templatetag
  • api
  • templatetags
  • yandex
  • maps
Read More

Silk icon tags

This simple template tag can be used to add famfamfam's silk icons easily to any element in your template.

  • templatetags
  • icons
  • silk
Read More

Smart widthratio

This is the same as [{% widthratio %}](http://docs.djangoproject.com/en/dev/ref/templates/builtins/#widthratio) but when the given value is greater than the max_value it just uses the max_value. This way the result is never greater than max_value. It also returns max_width if the max_value is 0 instead of returning a blank string. Usage example: {% smart_widthratio this_value max_value 100 %}

  • templatetag
  • widthratio
  • templatetags
Read More

Subdirectory and subcontext include template tag with examples

In principle it's a DRY code of a template node that can be used for creating project-wide template-tags. These can be used to display conceptually common blocks in templates with applications specific looks and content. E.g.: 1. application-specific info message, 2. model instances details in the list context, 3. login messages like 'Please login or signup to [some app-dependent text]' with appropriate url's, 4. standard forms (e.g with same CSS classes, displayed with uni_form). The code is profusely commented so look it up for details. Basically, when you have your project-wide `SubIncludeNode` tag defined, then just define appropriately named templates in applications template subdirectories e.g. `'profiles/_show_item.html'`. ** Example usage: login or signup message ** Let's say we are editing template rendered by the view indicated by the pattern named 'project_list' in the 'projects' app: {# those are equivalent #} {% login_or_signup %} {% login_or_signup project_list %} {% login_or_signup "project_list" %} {# academic purposes direct sub_include usage #} {# those two includes are also equivalent if there is no template called '_login_or_signup.html' in the 'projects' subdirectory #} {% url acct_signup as signup_url %} {% url acct_login as login_url %} {% url project_list as next_url %} {% sub_include "_login_or_signup.html" %} {% include "_login_or_signup.html" %} {# and those two are also equivalent if there is a template called '_login_or_signup.html' in the 'projects' subdirectory #} {% sub_include "_login_or_signup.html" from "projects" %} {% sub_include "_login_or_signup.html" %} {# also equivalent include if there is no variable called 'projects' in tempalte's context #} {% sub_include "_login_or_signup.html" from projects %} {# those are examples of using custom subcontext #} {% url acct_signup as signup_url %} {% url acct_login as login_url %} {% sub_include "_login_or_signup.html" from "default" with login_url,signup_url,next_url="/welcome" %} {% sub_include "_login_or_signup.html" with login_url="/login",next_url="/welcome",signup_url="/signup" %} ** Mored advanced usage proposal ** Say you have an subclasses of some model from the original app in a separate extending apps. You want to display subclasses instances differently using the original app templates. In the original app you do not know what the set of subclasses is (as the original app is not aware of the extending apps). Subclassing the `SubIncludeNode` you can override the `default_subdir` method such that it returns the app label of a model instance that was passed as a argument of your tag. This way you just put templates like `_show_instance.html` in extending apps subdirectories and voila - you have implementation of the overrideable templates displaying appropriately details about the model subclass instances.

  • templatetag
  • templatetags
  • include
Read More

Type checking templatetag filters

It's often useful to be able to check the type of an object in templates. Most recently I used this to do some trickery in my forms for certain field types. These template filters allow you to match the type of an object or a field widget with a string. It returns True if it matches and False if it doesn't or there is an error. for example: {% if form|obj_type:'mycustomform' %} <form class="custom" action=""> {% else %} <form action=""> {% endif %} {% if field|field_type:'checkboxinput' %} <label class="cb_label">{{ field }} {{ field.label }}</label> {% else %} <label for="id_{{ field.name }}">{{ field.label }}</label> {{ field }} {% endif %}

  • templatetags
Read More

Decorate Template Tag (In-Line include and extend with local context)

I had an issue with the django templating system, where by if I included several different files at the same level on one template.. and all the included templates extended the same base template. It would render the defined blocks for the first inclusion for all. i.e. everything in the parent that is being extended would be not updated for the subsequent inclusion. So, if anyone else has this problem. I have a solution that I sorta wanted for other reasons anyway. It's called a decorator tag, you can include and extend a template at the same time - in-line, with local context scoping so it only affects that tag. This is also a nice way to avoid creating .html files for simple extending purposes.

  • templatetags
  • extend
  • include
  • decorate
Read More

35 snippets posted so far.