Skip to content

Custom link in group does not render Jinja2 code #3857

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

Closed
rodvand opened this issue Jan 8, 2020 · 1 comment · Fixed by #3858
Closed

Custom link in group does not render Jinja2 code #3857

rodvand opened this issue Jan 8, 2020 · 1 comment · Fixed by #3858
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@rodvand
Copy link
Contributor

rodvand commented Jan 8, 2020

Environment

  • Python version: 3.6.8
  • NetBox version: 2.6.11

Steps to Reproduce

  1. Create a custom link and add it to a group. Make the name use Jinja style code - example {% if True %} Custom Link 1{% endif %}
  2. Open a device and look at the custom link

Expected Behavior

Expected the link to use the Jinja2 code and show "Custom Link 1" as name.

Observed Behavior

The Jinja code is shown as the name. So the name is "{% if True %} Custom Link 1{% endif %}" instead of "Custom Link 1". The link itself is also not rendering Jinja code.

This seems to come from #3461 and due to the text_rendered and link_rendered not being used in the format statement on

GROUP_LINK.format(cl.url, link_target, cl.text)

I did a quick check and changed

                text_rendered = render_jinja2(cl.text, context)
                if text_rendered:
                    link_target = ' target="_blank"' if cl.new_window else ''
                    links_rendered.append(
                        GROUP_LINK.format(cl.url, link_target, cl.text)
                    )

to

                text_rendered = render_jinja2(cl.text, context)
                if text_rendered:
                    link_target = ' target="_blank"' if cl.new_window else ''
                    link_rendered = render_jinja2(cl.url, context)
                    links_rendered.append(
                        GROUP_LINK.format(link_rendered, link_target, text_rendered)
                    )

This made it work as expected again.

@hSaria
Copy link
Contributor

hSaria commented Jan 8, 2020

Yeah, that seems to have been forgotten for grouped links. I'll raise a PR but you pretty much did all the work :)

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application labels Jan 9, 2020
jeremystretch added a commit that referenced this issue Jan 9, 2020
Fixes #3857: Fix group custom links rendering
@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants