Added the format template tag that does sprintf-like string format in the templates.
This commit is contained in:
parent
db860619f1
commit
d047be7ba9
@ -24,7 +24,8 @@ First written: 2020/7/1
|
|||||||
{% load humanize %}
|
{% load humanize %}
|
||||||
|
|
||||||
{% block settings %}
|
{% block settings %}
|
||||||
{% trans "Cash Report" context "Accounting|" as title %}
|
{% trans "Cash Account for {} in {}" context "Accounting|" as title_format %}
|
||||||
|
{% format title_format "庫存現金" period_parser.description as title %}
|
||||||
{% setvar "title" title %}
|
{% setvar "title" title %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -30,3 +30,19 @@ def setvar(context, key, value):
|
|||||||
"""
|
"""
|
||||||
context.dicts[0][key] = value
|
context.dicts[0][key] = value
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def format(context, format, *args, **kwargs):
|
||||||
|
"""Sets a variable in the template.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
context (Context): the context.
|
||||||
|
format (str): The format.
|
||||||
|
args (str): The parameters.
|
||||||
|
kwargs (str): The keyword arguments.
|
||||||
|
"""
|
||||||
|
if "as" in kwargs:
|
||||||
|
context.dicts[0][kwargs["as"]] = format.format(*args)
|
||||||
|
return ""
|
||||||
|
return format.format(*args)
|
||||||
|
Loading…
Reference in New Issue
Block a user