Use of genshi in email templates

I have a question regarding the use of genshi.
I want to make a hyperlink to a sale in an email template in order to redirect users to it. I want to do it directly on the text field throughout the user interface like this:
image
Also, I would like to iterate throughout a list of shipments of a sale to get the number from each of them. I know it is doable with a functional field, but I want to know if its doable directly.
I found some ways in the documentation but none work for me.

Could you explain precisely what you did, what did not work and what was the result and why it is not what you expect?

I expect to get a hyperlink to a sale, that this hyperlink has to appear at the body of the email template.
I tried the code that you can see on the picture. And when the mail arrives all that expression it’s literally a text, no hyperlink. And idk if there is way to do it.

The second thing that I need to do, is to take the shipments of a sale and iterate between them to get their numbers and show them on the body too, without creating a function field to get that.

The richtext widget does not support anchor element.

You can loop with the genshi text directives: Genshi Text Template Language — Genshi 0.7dev documentation

I tried to do that:

{% for shipment in ${record.shipments} %}\
   ${shipment.number}
{% end %}

But it results in an error when I open the email template from the sale.

Traceback (most recent call last):
  File "/trytond/wsgi.py", line 117, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/trytond/protocols/dispatcher.py", line 46, in rpc
    return methods.get(request.rpc_method, _dispatch)(
  File "/trytond/wsgi.py", line 84, in auth_required
    return wrapped(*args, **kwargs)
  File "/trytond/protocols/wrappers.py", line 159, in wrapper
    return func(request, pool, *args, **kwargs)
  File "/trytond/protocols/dispatcher.py", line 185, in _dispatch
    result = rpc.result(meth(inst, *c_args, **c_kwargs))
  File "/trytond/modules/party/ir.py", line 47, in get
    return super().get(record)
  File "/trytond/ir/email_.py", line 446, in get
    .render())
  File "/venv/lib/python3.10/site-packages/genshi/core.py", line 183, in render
    return encode(generator, method=method, encoding=encoding, out=out)
  File "/venv/lib/python3.10/site-packages/genshi/output.py", line 59, in encode
    return _encode(''.join(list(iterator)))
  File "/venv/lib/python3.10/site-packages/genshi/output.py", line 581, in __call__
    for event in stream:
  File "/venv/lib/python3.10/site-packages/genshi/core.py", line 291, in _ensure
    for event in stream:
  File "/venv/lib/python3.10/site-packages/genshi/template/base.py", line 641, in _include
    for event in stream:
  File "/venv/lib/python3.10/site-packages/genshi/template/base.py", line 601, in _flatten
    result = _eval_expr(data, ctxt, vars)
  File "/venv/lib/python3.10/site-packages/genshi/template/base.py", line 291, in _eval_expr
    retval = expr.evaluate(ctxt)
  File "/venv/lib/python3.10/site-packages/genshi/template/eval.py", line 160, in evaluate
    return eval(self.code, _globals, {'__data__': data})
  File "<string>", line -1, in <Expression 'shipment.number'>
  File "/venv/lib/python3.10/site-packages/genshi/template/eval.py", line 294, in lookup_name
    val = cls.undefined(name)
  File "/venv/lib/python3.10/site-packages/genshi/template/eval.py", line 397, in undefined
    raise UndefinedError(key, owner=owner)
genshi.template.eval.UndefinedError: "shipment" not defined

I think it is your subject rendering that is failing not the body.

Is this maybe related to Tryton is using the OldTextTemplate instead the NewTextTemplate (#11737) · Issues · Tryton / Tryton · GitLab? It means that the old syntax has to be used (Genshi Text Template Language — Genshi 0.7dev documentation).

It’s definitely related. But I tried to do a test using the OldTextTemplate with that:

#for item in [1, 2, 3]
 * $item
#end

And the same error results, as the other I posted.

genshi.template.eval.UndefinedError: "item" not defined

I replaced the import that you mention in the issue

from genshi.template import TextTemplate -----> from genshi.template.text import NewTextTemplate as TextTemplate

Did the following, and it worked. But I would like to know if if i’m doing something wrong using the OldTextTemplate.

{% for shipment in record.shipments %}
    $shipment.number, 
{% end %}

I want to make a oneline if with OldTextTemplate, how can I do it? Because I don’t find a lot references in the documentation. I tried with this, but if there is no project, it throws an error.

#if ${record.project} ${record.project.rec_name} #end