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

如何在TinyButStrong中正确编写条件?ODT模板渲染失效求助

Troubleshooting Your TinyButStrong ODT If Statement Issue

Let's break down the possible issues with your current TBS syntax and fix them step by step:

1. Wrong Quote Type (Chinese vs English)

You're using Chinese single quotes ‘’ in your then/else clauses, but TinyButStrong only recognizes English single/double quotes ('' or ""). Non-English quotes will break the syntax parser entirely.

2. Incorrect Mix of If Logic and Block Directive

Your current syntax jumbles the if condition and block parameter into one tag, which isn't the standard way to handle conditional block rendering in ODT. TBS expects the if condition to be attached directly to the block directive when you're controlling XML elements like table rows.

3. Unnecessary Quotes Around Variables

Wrapping [tab.product_ref] in quotes tells TBS to output the literal string (including the quotes) instead of parsing the variable. Unless you specifically want quotes around the product reference, remove them entirely.


Corrected Syntax Options

Try one of these valid approaches based on your exact needs:

Option 1: Conditionally Show/Hide Entire Table Rows

If you want to display the row only when product_type != 1, use this structure:

[block=table:table-row;if [tab.product_type]!=1]
    <!-- Your table cell content here -->
    <table:table-cell><text:p>[tab.product_ref]</text:p></table:table-cell>
[block]

To show 0 in a row when product_type == 1, add an else block:

[block=table:table-row;if [tab.product_type]!=1]
    <table:table-cell><text:p>[tab.product_ref]</text:p></table:table-cell>
[block=table:table-row;else]
    <table:table-cell><text:p>0</text:p></table:table-cell>
[block]

Option 2: Conditional Value Inside a Single Row

If you want the row to always appear, but switch between product_ref and 0 based on the condition, use an inline if directive inside the table cell:

<table:table-cell>
    <text:p>[if [tab.product_type]!=1;then [tab.product_ref];else 0;]</text:p>
</table:table-cell>

Additional Quick Checks

  • Ensure your TBS tag is placed directly inside the <table:table-row> element it's targeting (not outside the XML node).
  • Double-check that tab.product_type exactly matches the variable name passed from the PHP side (TBS variables are case-sensitive!).
  • Remove any extra spaces or special characters in the TBS syntax that might confuse the parser.

内容的提问来源于stack exchange,提问作者acropose-corentin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 21:57:33