General Discussion

  • 1.  Freemarker - Filter Repeatable Section Content

    Adopter
    Posted 28 days ago

    Currently trying to create a customized PDF using freemarker. So far so good except for the repeatable section. I am unsure how to filter the results out using the truecontext syntax.

    Basically, we have a list in a repeatable section with a question Add Topic (YES/NO button). If Yes is selected, then I have the paragraph auto-add to the PDF.  Anyone know how to filter out results of a Repeatable Section in freemarker?

    <#list dataRecord.pages.SLForm.sections.SLTTable.rows as row> ${(row.pages.SafetyLetterTopics.sections.SLTSubTable.answers.SLTopic.values[0])!""} - ${(row.pages.SafetyLetterTopics.sections.SLTSubTable.answers.SLParagraph.values[0])!""}



    ------------------------------
    Luke Greene
    KONE
    ------------------------------


  • 2.  RE: Freemarker - Filter Repeatable Section Content

    Staff
    Posted 28 days ago
    Edited by Scott Daly 28 days ago

    Hi Luke,

    One approach would be to wrap your SLTopic and SLParagraph output statements in an IF statement which will check to see if your Add Topic question is a certain value (ie. if it's Yes, then print the Topic and Paragraph, otherwise ignore it). The freemarker code for this would look something like this:

    <#list dataRecord.pages.SLForm.sections.SLTTable.rows as row> 
        <#if (row.pages.SafetyLetterTopics.sections.SLTSubTable.answers.AddTopic_QUESTION_LABEL.values[0].display == "YES")>
            ${(row.pages.SafetyLetterTopics.sections.SLTSubTable.answers.SLTopic.values[0])!""} - ${(row.pages.SafetyLetterTopics.sections.SLTSubTable.answers.SLParagraph.values[0])!""}
        </#if>
    </#list>

    Hope this helps!



    ------------------------------
    Scott Daly
    Senior Manager, Implementation Services
    TrueContext
    ------------------------------



  • 3.  RE: Freemarker - Filter Repeatable Section Content

    Adopter
    Posted 27 days ago

    Hey Scott, thanks so much for the reply! I dabbled with your solution but getting the following error "The following has evaluated to null or missing: ==> row.pages.SLTTable.sections.SLTSubTable.answers.AddTopic_QUESTION_LABEL [in template "body template for Document 'null' (null)"

    The question AddTopic defaults to "No" in the repeatable section. It is a button with yes no. I tried changing the field type to checkbox but still failing out. This might be what Calvin mentioned below in terms of referencing expected answers but not sure. 

    <#list dataRecord.pages.Conclusion.sections.SafetyLetterTopics.rows as row>
    <#if (row.pages.SLTTable.sections.SLTSubTable.answers.AddTopic_QUESTION_LABEL.values[0] == "Yes")>
         
         
      <u>${(row.pages.SLTTable.sections.SLTSubTable.answers.SLTopic.values[0])!""} </u>
      - 
      ${(row.pages.SLTTable.sections.SLTSubTable.answers.SLParagraph.values[0])!""}<br><br>
      </#if>   
    </#list>


    ------------------------------
    Luke Greene
    Risk Analyst
    KONE
    ------------------------------



  • 4.  RE: Freemarker - Filter Repeatable Section Content

    Adopter
    Posted 28 days ago

    Looks like Scott has got you covered but I'll chime in to add that if you have to do this a lot in your document, its worth creating a re-usable macro. Some other tips below as well - I can only add one code block for some reason so my apologies for the formatting below.

    <#macro conditionalParagraph question paragraph expectedAnswer="YES">
    <#if question.values[0]!"" == expectedAnswer>
     <p>${question.values[0]!""} - ${paragraph.values[0]!""}</p>
    </#if>
    </#macro>
    
    // Use it like this:
    
    <#list dataRecord.pages.SLForm.sections.SLTTable.rows as row>
        <@conditionalParagraph question=row.pages.SafetyLetterTopics.sections.SLTSubTable.answers.SLTopic paragraph=row.pages.SafetyLetterTopics.sections.SLTSubTable.answers.SLParagraph />
    </#list>
    
    // If you expected the answer to be something other than "YES", you can add expectedAnswer="YOURANSWER"
    // the default is YES though, so you can omit it if that's what you expect.
    
    // Also another tip - if you are working in a section a lot, you can save yourself some typing and make the template cleaner 
    // by assigning it to a variable rather than typing out the whole path:
    
    <#assign section = row.pages.SafetyLetterTopics.sections.SLTSubTable.answers>    
    
    // And then you can refer to questions in that section like so:
    
    ${section.SLTopic.values[0]!""}
    // instead of:
    ${row.pages.SafetyLetterTopics.sections.SLTSubTable.answers.SLTopic.values[0]!""}
    
    // It's as close to a "with" statement as you can get with FTL. If you're going to be referring to a specific section frequently throughout 
    // the document, you can also just assign it with a unique variable name like below and use it as an "alias" throughout the document.
    
    <#assign SLTTable = dataRecord.pages.SLForm.sections.SLTTable>    
    <#list SLTTable.rows as row>
        <#assign this = row.pages.SafetyLetterTopics.sections.SLTSubTable.answers>    
        <@conditionalParagraph question=this.SLTopic paragraph=this.SLParagraph />
    </#list>


    ------------------------------
    Calvin Hunter
    Project Manager
    Vipond Inc
    calvin.hunter@vipond.ca
    ------------------------------



  • 5.  RE: Freemarker - Filter Repeatable Section Content

    Adopter
    Posted 27 days ago

    Thanks Calvin for the thoughtful response! Was able to get the solution to work using the macro! Much appreciated!



    ------------------------------
    Luke Greene
    Risk Analyst
    KONE
    ------------------------------



Reminder: Content posted to our Community is public content.  Please be careful not to post Intellectual Property that you do not have permission to share.  For more information please refer to our Terms Of Use