Custom link in group does not render Jinja2 code #3131

Closed
opened 2025-12-29 18:25:58 +01:00 by adam · 1 comment
Owner

Originally created by @rodvand on GitHub (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 b5455ed882/netbox/extras/templatetags/custom_links.py (L72)

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.

Originally created by @rodvand on GitHub (Jan 8, 2020). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.6.8 * NetBox version: 2.6.11 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a wrapper like pynetbox. --> ### 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 <!-- What did you expect to happen? --> ### Expected Behavior Expected the link to use the Jinja2 code and show "Custom Link 1" as name. <!-- What happened instead? --> ### 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 https://github.com/netbox-community/netbox/blob/b5455ed882c47273064933f0120b0e368af93a1f/netbox/extras/templatetags/custom_links.py#L72 I did a quick check and changed ```try: 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 ```try: 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.
adam added the type: bugstatus: accepted labels 2025-12-29 18:25:58 +01:00
adam closed this issue 2025-12-29 18:25:58 +01:00
Author
Owner

@hSaria commented on GitHub (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 :)

@hSaria commented on GitHub (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 :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3131