I know this is an old question, but after 3 hours of scouring the internet and finding no examples, I wanted to make sure it got documented.
Going back to one of your original attempts:
{{ attribute(lang, get, 'test') }}
I'm trying to do the same thing, and this should work according to the documentation. Unfortunately, there are no examples of using this. All I found was that the method name (get) had to be a string ('get'), so I changed that, but it still didn't work. What I ended up doing was this:
{% set myText = lang.get('test') %}
{{ myText }}
This worked great, but it's a lot of code to write when I have to do this all over. So I made a simple template with both methods and examined the compiled output. The original was compiled to this:
echo twig_escape_filter($this->env, $this->getAttribute((isset($context["lang"]) ? $context["lang"] : null), "get", "test"), "html", null, true);
and the second (2 liner) to this:
$context["myText"] = $this->getAttribute((isset($context["lang"]) ? $context["lang"] : null), "get", array(0 => "test"), "method");
echo twig_escape_filter($this->env, (isset($context["myText"]) ? $context["myText"] : null), "html", null, true);
After examination, I realized the difference (check the 3rd parameters to getAttribute), the arguments parameter is an array! This is good information to know. I changed my original to this:
{{ attribute(lang, 'get', ['test']) }}
and it's now working!
Hope this helps someone!
lang.get('test')
? – Maerlyn{% for TNS in tnm.getTNservice(user_id) %} {{ TNS.tn_id }} {% for TNP in tnm.getTNpublications(TNS.tn_id) %} {{ TNP.publication_id }} {% endfor %} {% endfor %}
– digitaltoast