Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When I was doing plain PHP, I was simply doing this:

printf(_("Hello %s !"), $name);

Now with Twig, I must use the trans tag. So I've copy/paste the documentation example, and here's my full template:

{% extends 'MyAppBundle::layout.html.twig' %}

{% block content %}
    <h1>
        {% trans %}
            Hello {{ name }}!
        {% endtrans %}
    </h1>
{% endblock %}

Why Symfony return the following exeption ?

A message must be a simple text in "MyAppBundle::home.html.twig"

500 Internal Server Error - Twig_Error_Syntax

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

One missing bit with the previous answer is the "with" portion that is needed to do the replacement of the variable part of the message.

{% trans with {'%name%':name} %}Hello %name%!{% endtrans %}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...