简体   繁体   English

Adobe Document Generation 中同一行的条件逻辑无法识别模板标签

[英]Conditional logic on the same line in Adobe Document Generation is not recognizing template tags

I have a json field that is either absent or is set to true .我有一个 json 字段不存在或设置为true But in my document I want it to show up as "Yes" or "No".但在我的文档中,我希望它显示为“是”或“否”。 I tried the following conditional expression ():我尝试了以下条件表达式():

{% conditional-section expr(`my_field` = true) %}Yes{% end-section %}{% conditional-section expr(`my_field`!= true) %}No{% end-section %}

But when I call the Adobe Document Generation API, the PDF I get still has these template tags.但是当我调用 Adobe Document Generation API 时,我得到的 PDF 仍然有这些模板标签。 For some reason it is not being detected.由于某种原因,它没有被检测到。 How can I achieve this?我怎样才能做到这一点?

I know I asked a question above in the comment, but I think I can take a stab at answering this now.我知道我在上面的评论中问了一个问题,但我想我现在可以尝试回答这个问题。 So right now there is not a way to say "if a value is NOT present or present and equal to yes."所以现在没有办法说“如果一个值不存在或不存在并且等于是”。 There's a few ways you can handle this, but I think the easiest would be to change your data.有几种方法可以解决这个问题,但我认为最简单的方法是更改数据。 To be clear, I don't mean change your database or anything, but keep in mind that before you call our API, you can massage the data a bit.需要明确的是,我并不是说要更改您的数据库或其他任何东西,但请记住,在您致电我们的 API 之前,您可以稍微处理一下数据。 So if the absence of my_field means yes, I'd do something like this (JavaScript):因此,如果缺少my_field意味着是,我会做这样的事情(JavaScript):

if(!mydata.my_field) {
  mydata.my_field = 'yes';
}

You could then do something like this:然后你可以做这样的事情:

{% conditional-section expr(my_field = "yes") %}
Yes
{% end-section %}
{% conditional-section expr(my_field = "no") %}
No
{% end-section %}

However, this will not be on the same line.但是,这不会在同一条线上。 As I said, this is a known issue.正如我所说,这是一个已知问题。 If you need it as such, again, I'd use the idea of massaging your data first.如果您需要它,我会再次使用首先按摩您的数据的想法。 You could do something like this (again, JavaScript, but could be done in any language):你可以这样做(同样,JavaScript,但可以用任何语言完成):

if(!mydata.my_field) {
  mydata.my_field = 'yes';
}
if(mydata.my_field === 'yes') mydata.my_field_value = 'Yes';
else mydata.my_field_value = 'No';

All I did there was, based on the value of my_field, set another variable.我所做的只是根据 my_field 的值设置另一个变量。 In your Word template you can then simplify even more by just using {{my_field_value}}在您的 Word 模板中,您可以通过使用{{my_field_value}}来进一步简化

With Document Generation being so flexible, you've got multiple different ways of solving a problem.由于文档生成如此灵活,您有多种不同的方法来解决问题。

I have found this works for me:我发现这对我有用:

{{my_field ? "Yes" : "No"}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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