简体   繁体   中英

How to print a variable that has a whitespace in its name in Jtwig/Twig?

Let's say I have a model in JSON:

{"Id": 123, "Full Name": "Foo Bar"}

I can output the value of Id in Jtwig like so: {{ Id }}

But how do I output the value of Full Name ?

So after reading the official docs and very few posts around the Internet that are vaguely related I've figured out there is no way to do it without the changes in the Jtwig core . The only solution would be to modify the input model for the template by embedding it in a variable that has a valid identifier name, for example:

{"data": {"Id": 123, "Full Name": "Foo Bar"}}

Then we can use {{ data.Id }} and {{ data['Full Name'] }} in the template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM