template filter to split string

795 views
Skip to first unread message

Markus Gattol

unread,
Jul 19, 2012, 12:36:58 PM7/19/12
to django...@googlegroups.com
within the head section of my base.html I am using

        <title>
            {% block title %}
                {% if request.path_info == '/' %}
                    home
                {% else %}
                    {{ request.path_info | slugify }}
                {% endif %}
            {% endblock %}
        </title>

to set the title of a page. Certainly slugify isn't perfect so I am looking for a filter to turn the request.path string from e.g. /foo/baz/bar into bar Is there an easy way to do this or will I end up writing my own filter?

Kurtis Mullins

unread,
Jul 19, 2012, 2:13:16 PM7/19/12
to django...@googlegroups.com
You could create a custom template tag to do this. Then just do something like

{% load page_title %}
...
{{ page_title }}

Or create a context middleware that will always creates a variable with the proper data.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/qqi9dTGtc5UJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply all
Reply to author
Forward
0 new messages