首页 > 解决方案 > 两种不同标签的液体过滤器

问题描述

如果满足另一个占位符的条件,我需要创建一个液体标签/过滤器,它仅显示占位符中所需的数据。

实际:我有一个包含不同问题和不同答案的网络表单。

问题有占位符:{{attendees[0].custom_questions[0].name}}

答案具有占位符:{{attendees[0].custom_questions[0].answer}}

-> 只有一个与会者,所以与会者[0] 不会改变。

-> custom_questions.name 和 custom_questions.answer 的顺序可以改变。

-> 有 15 个不同的问题和答案

预期:如果 custom_questions.name == "Test Question" 则应显示该问题的 custom_questions.answer "Test Answer"。

澄清:

如果“测试题”是 fe {{attendees[0].custom_questions[8].name}},则正确答案是 {{attendees[0].custom_questions[8].answer}}

但是 “测试问题”有时也可以是 {{attendees[0].custom_questions[9].name}} 或数组中的其他数字。

仅当 question == "Test question" 时才应显示答案

有人可以帮忙吗?

更新

我正在使用基本的 html 编辑器来创建 pdf 文件。此编辑器使用液体标签作为数据库中的占位符。该数据库由网络表单填写。占位符(来自数据库)无法编辑。

代码示例:

<table style="width: 100%; border-collapse: collapse; height: 13px;" border="0">
<tbody>
<tr style="height: 13px;">
<td style="width: 100%; height: 13px; text-align: center;"><span style="font-size: 18pt; position: relative; left: -0.5cm;">VOUCHER FOR {% for p in attendees %} {% if p.ticket.id == "103391" or p.ticket.id == "103411" or p.ticket.id == "103392" %} PRESS BADGE {% else %} VIP PRESS INVITATION {% endif %} {% endfor %}</span></td>
</tr>
</tbody>
</table>

在这段代码中,您可以看到液体代码的用法。

对于这项任务,我需要使用两个不同的占位符:

{{参加者[0].custom_questions[0].name}}

{{参加者[0].custom_questions[0].answer}}

这些阵列只有一名与会者,但最多有 15 个问题。

不幸的是,订单并不稳定。有时需要的答案是数字 4,有时是数字 9。

我需要一个名为“测试问题”的问题的答案。
答案占位符将始终具有与问题名称相同的数组编号。

我的想法:

{% if attendees[0].custom_questions[0].name == "Test Question" %}{{attendees[0].custom_questions[0].answer}}{% elsif attendees[0].custom_questions[1].name == "Test Question"%}{{attendees[0].custom_questions[1].answer}}{% elsif attendees[0].custom_questions[2].name == "Test Question"%}{{attendees[0].custom_questions[2].answer}}..........

不工作。

你能帮我吗?

标签: liquid

解决方案


推荐阅读