1

I have inherited a large number of .yaml files that contain an attribute like this:

our_price: Our price is just <sup>$</sup><span class="amount">99.95</span> this month

Now, the client wants to be able to take our_price, add some taxes and fees, and display a total price in the jinja templates.

What I'd like to do is add a new attribute, so it looks like this:

simple_price: 99.95
our_price: Our price is just <sup>$</sup><span class="amount">simple_price</span> this month

I've tried using aliases, but it seems they only work as the entire value of the node.

Is there a way to set this up in YAML, or a way to pull out just the float from the our_price string in jinja2?

4

1 回答 1

0

尽管我对 jinja 一无所知,但我认为您的问题在概念上与此 StackOverflow question相似。

简短的回答是,您不能按照您/您的客户想要的方式在 YAML 中进行字符串插值。我相信您必须将simple_price值传递给our_price视图文件(或 jinja 等效文件)中的值,并将 YAML 条目更改为:

simple_price: 99.95
our_price: Our price is just <sup>$</sup><span class="amount">%{simple_price}</span>

或者,使用别名和锚点,您可以将价格和字符串作为数组带回视图,然后将它们连接成一个字符串:

simple_price: &simple_price <sup>$</sup><span class="amount">99.95</span>
our_price: 
  - Our price is just
  - *simple_price
于 2012-12-23T02:39:16.507 回答