Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access to project from a simple_tag? #66

Open
PaulPichaureau opened this issue Feb 15, 2018 · 2 comments
Open

How to access to project from a simple_tag? #66

PaulPichaureau opened this issue Feb 15, 2018 · 2 comments
Milestone

Comments

@PaulPichaureau
Copy link
Contributor

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 viewsin 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) )
    (...)
@thanethomson
Copy link
Owner

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.

@PaulPichaureau
Copy link
Contributor Author

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.

@thanethomson thanethomson added this to the v0.23.0 milestone Jan 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants