statik
statik copied to clipboard
How to access to project from a simple_tag?
I'm trying to code a link
tag which creates a complete url link.
{% link "page" my-page %}
is supposed to create
page title
But I don't know how to access to views
in the code of the tag:
@register.simple_tag(name='link')
def tag_link(*args):
views = ???
view_name, inst = args
url = add_url_path_component("/", views[view_name].reverse_url(inst) )
(...)
Would this do something that the url
tag wouldn't? See the wiki here. The usage is a little different to what you're trying to achieve, however.
Usage (for example, when iterating through pages):
{% for page in pages %}
<a href="{% url "pages-view-name", page.pk %}">{{ page.title }}</a>.
{% endfor %}
See the code for the extension here.
Well, I was playing around with the code...
My idea is to have some sort of macro to cite quickly a page. Essentially, to obtain the result of
<a href="{% url "pages-view-name", page.pk %}">{{ page.title }}</a>.
in one command.