Update all templates to use the button templatetag #3065

Closed
opened 2025-12-29 18:25:17 +01:00 by adam · 3 comments
Owner

Originally created by @jeremystretch on GitHub (Dec 13, 2019).

Originally assigned to: @jeremystretch on GitHub.

Proposed Changes

Update all templates to use the custom {% xxx_button %} tag for creating links to add/edit/delete objects.

Justification

This replaces many instances of boilerplate code and reduces the opportunity for error.

Originally created by @jeremystretch on GitHub (Dec 13, 2019). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes Update all templates to use the custom `{% xxx_button %}` tag for creating links to add/edit/delete objects. ### Justification This replaces many instances of boilerplate code and reduces the opportunity for error.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 18:25:17 +01:00
adam closed this issue 2025-12-29 18:25:17 +01:00
Author
Owner

@hSaria commented on GitHub (Dec 14, 2019):

Shall I do the same for the copy button? It'll make it easier to dot copy buttons in other places, like the shipping address of a site, or the rendered config context of a device.

@hSaria commented on GitHub (Dec 14, 2019): Shall I do the same for the copy button? It'll make it easier to dot copy buttons in other places, like the shipping address of a site, or the rendered config context of a device.
Author
Owner

@jeremystretch commented on GitHub (Dec 16, 2019):

@hSaria maybe, but it might be more difficult given that the copy buttons aren't always in a standard location, and they have to reference other elements. Take a shot at it if you think it's worthwhile.

@jeremystretch commented on GitHub (Dec 16, 2019): @hSaria maybe, but it might be more difficult given that the copy buttons aren't always in a standard location, and they have to reference other elements. Take a shot at it if you think it's worthwhile.
Author
Owner

@hSaria commented on GitHub (Dec 16, 2019):

Yeah, I thought about this for a bit and I can think of two ways to do it:

  1. Create different variants (lots of duplicate code, so probably not this)
  2. Use additional arguments to dictate the output, like so:

btn-clipboardjs to be used by ClipboardJS for event delegation

# template
<a class="btn btn-clipboardjs {{ style }}" data-clipboard-target="{{ target }}">
    <span class="fa fa-copy" aria-hidden="true"></span>{% if verbose %} Copy {% endif %}
</a>

# example usage
{% copy_button 'shipping_address' 'btn-xs' verbose=True %}
               ^ target           ^ style  ^ kwargs

It's really up to you. I just saw this ticket and thought "Huh... Neat." It depends if you think we'll get more instances of #3761 and #2638, perhaps on data that is not human-friendly (e.g. serial number) or where accuracy is needed (e.g. shipping address), but again, I'll leave this for you to decide as you'll know what's best for the project – I'm happy to help where I can :)

@hSaria commented on GitHub (Dec 16, 2019): Yeah, I thought about this for a bit and I can think of two ways to do it: 1. Create different variants (lots of duplicate code, so probably not this) 2. Use additional arguments to dictate the output, like so: > `btn-clipboardjs` to be used by ClipboardJS for event delegation ``` # template <a class="btn btn-clipboardjs {{ style }}" data-clipboard-target="{{ target }}"> <span class="fa fa-copy" aria-hidden="true"></span>{% if verbose %} Copy {% endif %} </a> # example usage {% copy_button 'shipping_address' 'btn-xs' verbose=True %} ^ target ^ style ^ kwargs ``` It's really up to you. I just saw this ticket and thought "Huh... Neat." It depends if you think we'll get more instances of #3761 and #2638, perhaps on data that is not human-friendly (e.g. serial number) or where accuracy is needed (e.g. shipping address), but again, I'll leave this for you to decide as you'll know what's best for the project – I'm happy to help where I can :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3065