Search code examples
adobe-documentgeneration

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. 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. For some reason it is not being detected. How can I achieve this?


Solution

  • 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. So if the absence of my_field means yes, I'd do something like this (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):

    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. In your Word template you can then simplify even more by just using {{my_field_value}}

    With Document Generation being so flexible, you've got multiple different ways of solving a problem.