Skip to content

[FR] Custom templatetags in labels #5052

Closed as not planned
Closed as not planned

Description

@DS1705

Please verify that this feature request has NOT been suggested before.

  • I checked and didn't find a similar feature request

Problem statement

i wanna use a custom templatetag inside of my label. to display the voltage 0.1V as 100mV the code is below. Is this possible and if it is how do i do it?

 `
from django import template
import sys
register = template.Library()


@register.filter(name="displayunits")
def displayunits(value):
if value>=10**6:
        return value/10**6+'M'
    if value>=10**3:
        strvalue=str(value/10**3)
        if '.' in strvalue:
            return strvalue.replace('.','k')    
        return value/10**3+'k'
    if value<10**3 and value>10**-3:
        return value
    if value>=10**-3:
        return value/10**-3+'m'
    if value>=10**-6:
        return value/10**-6+'µ'
    if value>=10**-9:
        return value/10**-9+'n'
    if value>=10**-12:
        return value/10**-12+'p'

`

Suggested solution

i just wan't to know if it is possible

Describe alternatives you've considered

i tried adding the template tag in map templatetags i created in the map of the label app but it didn't work

Examples of other systems

No response

Do you want to develop this?

  • I want to develop this.

Activity

  1. added
    enhancement
    triage:not-checked
    on Jun 15, 2023
  2. added
    report
    and removed
    triage:not-checked
    on Jun 15, 2023
  3. changed the title [-][FR] costum templatetags in labels[/-] [+][FR] Custom templatetags in labels[/+] on Jun 15, 2023
  4. matmair commented on Jun 15, 2023

    @matmair
    Member

    @DS1705 I do not really understand how you are trying to achieve your goal. In what kind of plugin (AppMixin, ReportMixin) did you insert this code? How is it loaded?
    What guide did you follow / where did you copy this code from? It seems logical at first but I do not think it will work this way. In general, we should be able to get this running pretty fast.

  5. added
    question
    and removed
    enhancement
    on Jun 15, 2023
  6. DS1705 commented on Jun 16, 2023

    @DS1705
    Author
  7. matmair commented on Jun 16, 2023

    @matmair
    Member

    @DS1705 the tag code itself is fine. I just do not see how InvenTree would discover the tag this way. Where did you place this code? In a plugin or in /plugins?

  8. DS1705 commented on Jun 20, 2023

    @DS1705
    Author

    i found the location i put my tag in report.py in templatetags under report

  9. wolflu05 commented on Jun 20, 2023

    @wolflu05
    Member

    That is not a very good solution because it makes upgrading much harder because you have to deal with conflicts. You could use an appmixin plugin to define your tags or @matmair what about adding a template tag Mixin?

  10. SchrodingersGat commented on Jun 20, 2023

    @SchrodingersGat
    Member

    We have a ReportMixin which is useful for adding custom context data to a report (or label).

    Perhaps this mixin could be extended to also add custom methods (tags) which can be called from the template?

  11. matmair commented on Jun 20, 2023

    @matmair
    Member

    A mixin is one possible solution, you could also just use a simple plugin, import the library register of *any templatetag and register your tags against that. in either the init() or the plugin class.

  12. github-actions commented on Aug 20, 2023

    @github-actions
    Contributor

    This issue seems stale. Please react to show this is still important.

  13. added
    inactive
    on Aug 20, 2023
  14. SchrodingersGat commented on Aug 21, 2023

    @SchrodingersGat
    Member

    not stale

  15. removed
    inactive
    on Aug 21, 2023
  16. github-actions commented on Oct 21, 2023

    @github-actions
    Contributor

    This issue seems stale. Please react to show this is still important.

  17. added
    inactive
    on Oct 21, 2023
  18. wolflu05 commented on Oct 28, 2023

    @wolflu05
    Member

    Not stale

  19. cpknight commented on Apr 10, 2026

    @cpknight

    For anyone who lands here looking for a way to add custom template tags to InvenTree reports and labels — we've published an open-source plugin that does exactly this:

    tarn-inventree-report-list-filters

    It adds two simple_tag functions — {% tarn_split %} and {% tarn_replace %} — that are available via the standard {% load report %} directive. The approach follows @matmair 's suggestion from this thread: the plugin imports InvenTree's report.templatetags.report.register at module level and registers the tags directly against it. This makes the tags appear automatically alongside InvenTree's built-in helpers. Both tags can be individually enabled/disabled from Plugin Settings in the System Settings.

    Example — splitting a pipe-delimited parameter into a list:

    {% load report %}
    {% tarn_split features.data "|" as items %}
    {% for item in items %}
      <li>{{ item }}</li>
    {% endfor %}

    Install: git+https://github.com/cpknight/tarn-inventree-report-list-filters.git

  20. SchrodingersGat commented on Apr 10, 2026

    @SchrodingersGat
    Member

    @cpknight string functions like this seem like good general purpose additions to the core codebase. I might look into adding these to the existing supported tags

  21. cpknight commented on Apr 13, 2026

    @cpknight

    @cpknight string functions like this seem like good general purpose additions to the core codebase. I might look into adding these to the existing supported tags

    @SchrodingersGat Yes, please! I've been meaning to put together something more generalized that I could submit over as a PR, but I've been really pressed for time lately and everything I have at the moment (automated integration for firmware burning, lots of report and label templates, automated test data workflows) is sort of half-baked at the moment (works mostly for me, but I need to make it usable for everyone else). I'll get there!

  22. SchrodingersGat commented on Apr 13, 2026

    @SchrodingersGat
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    inactivequestionreport

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions