You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PDF模板If else条件失效:无法按自定义表单显示对应签名

问题分析与解决方案

核心问题:字符串匹配不匹配

你代码里判断的是customform == "Stock Requisition",但需求里的目标表单是Store Requisition,拼写差异导致条件永远不触发,所以一直走else分支显示Supervisor Signature。

修复步骤

1. 修正判断字符串

把条件里的"Stock Requisition"改成"Store Requisition",这是最直接的修复:

<#if customform == "Store Requisition">
    <p>Stores Signature:</p>
    <#assign signatureSet = true>
<#else>
    <p>Supervisor Signature:</p>
    <#assign signatureSet = true>
</#if>

2. 验证字段取值准确性

如果修正后还是有问题,需要确认result.formulatext_1是否真的存储了自定义表单的名称:

  • 临时添加调试输出,查看实际取值:
    <#-- 调试用:输出实际拿到的表单名称 -->
    <p>Debug: Custom Form Value = ${result.formulatext_1!""}</p>
    
  • 检查是否有大小写、前后空格的问题,比如实际值带首尾空格,可以用trim()处理:
    <#assign customform = result.formulatext_1?trim>
    

3. 优化逻辑(可选)

因为只需要处理第一个有效结果,没必要遍历所有results,可以简化逻辑:

<#if results?size != 0>
    <table style="padding: 0.2in 0.01in 0.01in 0.02in; border-collapse: collapse;" cellpadding="1" cellspacing="1.5">
        <tbody>
            <tr>
                <td style="font-size:9pt">
                    <#assign signatureSet = false>
                    <#-- 直接取第一个结果处理 -->
                    <#assign firstResult = results?first>
                    <#if firstResult.formulatext_1??>
                        <#assign customform = firstResult.formulatext_1?trim>
                        
                        <#if customform == "Store Requisition">
                            <p>Stores Signature:</p>
                        <#else>
                            <p>Supervisor Signature:</p>
                        </#if>
                        <#assign signatureSet = true>
                    </#if>
                    <#if !signatureSet>
                        <p>Supervisor Signature</p>
                    </#if>
                </td>
            </tr>
        </tbody>
    </table>
</#if>

内容的提问来源于stack exchange,提问作者She Codes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 04:57:11