You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
@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.
@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?
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?
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.
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:
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 %}
@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
@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!
Activity
[-][FR] costum templatetags in labels[/-][+][FR] Custom templatetags in labels[/+]matmair commentedon Jun 15, 2023
@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.
DS1705 commentedon Jun 16, 2023
https://docs.djangoproject.com/en/4.2/howto/custom-template-tags/
that is what i try to do
i updated the code there was something not right
matmair commentedon Jun 16, 2023
@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?DS1705 commentedon Jun 20, 2023
i found the location i put my tag in report.py in templatetags under report
wolflu05 commentedon Jun 20, 2023
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?
SchrodingersGat commentedon Jun 20, 2023
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?
matmair commentedon Jun 20, 2023
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.
github-actions commentedon Aug 20, 2023
This issue seems stale. Please react to show this is still important.
SchrodingersGat commentedon Aug 21, 2023
not stale
github-actions commentedon Oct 21, 2023
This issue seems stale. Please react to show this is still important.
wolflu05 commentedon Oct 28, 2023
Not stale
cpknight commentedon Apr 10, 2026
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-filtersIt 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'sreport.templatetags.report.registerat 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.gitSchrodingersGat commentedon Apr 10, 2026
@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
cpknight commentedon Apr 13, 2026
@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!
SchrodingersGat commentedon Apr 13, 2026
1.3.0 has been released with a bunch of new report tags - https://docs.inventree.org/en/stable/report/helpers/