Example in jinja2 conditional rendering for custom URLs has typo #2867

Closed
opened 2025-12-29 18:22:56 +01:00 by adam · 2 comments
Owner

Originally created by @ctullos on GitHub (Sep 12, 2019).

Change Type

[x] Addition
[x] Correction
[ ] Deprecation
[ ] Cleanup (formatting, typos, etc.)

Proposed Corrections


For example, if you only want to display a link for active devices, you could set the link text to

{% if device.status == 1 %}View NMS{% endif %}

example should state:

{% if obj.status == 1 %}View NMS{% endif %}

Proposed Additions


  • Custom URLs are a very useful feature, coupled with Jinja2 templating it is very extensible. Can you please provide a few more examples and/or pointer to the subclasses that can be called?

For instance, I wanted to conditionally render based on device type. So I tried:

{% if obj.type == 1 %}View NMS{% endif %}

instead of:

{% if obj.device_type.model == 'TESTNAME' %}View NMS{% endif %}
Originally created by @ctullos on GitHub (Sep 12, 2019). <!-- Please indicate the nature of the change by placing an X in one of the boxes below. --> ### Change Type [x] Addition [x] Correction [ ] Deprecation [ ] Cleanup (formatting, typos, etc.) <!-- Describe the proposed change(s). --> ### Proposed Corrections ---------------------------------------------------------------------------------------------------------- * Please correct typo in existing documentation (see below) https://netbox.readthedocs.io/en/stable/additional-features/custom-links/#custom-links ``` For example, if you only want to display a link for active devices, you could set the link text to {% if device.status == 1 %}View NMS{% endif %} ``` example should state: ``` {% if obj.status == 1 %}View NMS{% endif %} ``` ### Proposed Additions ---------------------------------------------------------------------------------------------------------- * Custom URLs are a very useful feature, coupled with Jinja2 templating it is very extensible. Can you please provide a few more examples and/or pointer to the subclasses that can be called? For instance, I wanted to conditionally render based on device type. So I tried: ``` {% if obj.type == 1 %}View NMS{% endif %} ``` instead of: ``` {% if obj.device_type.model == 'TESTNAME' %}View NMS{% endif %} ```
adam added the status: acceptedtype: documentation labels 2025-12-29 18:22:56 +01:00
adam closed this issue 2025-12-29 18:22:56 +01:00
Author
Owner

@DanSheps commented on GitHub (Sep 13, 2019):

obj.device_type.name is not a valid path, it would have to be:

obj.device_type

or

obj.device_type.model

@DanSheps commented on GitHub (Sep 13, 2019): obj.device_type.name is not a valid path, it would have to be: obj.device_type or obj.device_type.model
Author
Owner

@ctullos commented on GitHub (Sep 13, 2019):

sorry about that, updated OP to reflect obj.device_type.model

@ctullos commented on GitHub (Sep 13, 2019): sorry about that, updated OP to reflect obj.device_type.model
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2867