Repository: netbox-community/netbox

Issue:
Custom link in group does not render Jinja2 code
<!--
    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.


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

Resolving patch:
diff --git a/netbox/extras/templatetags/custom_links.py b/netbox/extras/templatetags/custom_links.py
--- a/netbox/extras/templatetags/custom_links.py
+++ b/netbox/extras/templatetags/custom_links.py
@@ -68,8 +68,9 @@ def custom_links(obj):
                 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(cl.url, link_target, cl.text)
+                        GROUP_LINK.format(link_rendered, link_target, text_rendered)
                     )
             except Exception as e:
                 links_rendered.append(


Test patch: