> ## Documentation Index
> Fetch the complete documentation index at: https://foliant-help.iforiti.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Liquid 过滤器

> Foliant 新增的 Liquid 过滤器，用于金额、日期、措辞、地址、图片、条形码、数字和颜色。

过滤器用于改变值的打印方式。您可以在值后面用竖线添加过滤器：`{{ total_price | money }}`。您也可以将多个过滤器串联使用：`{{ note | escape | newline_to_br }}`。Foliant 支持 Liquid 的标准过滤器（例如 `escape`、`default`、`upcase`、`date`、`plus`、`minus`、`split`、`join`、`newline_to_br`），并新增了以下过滤器。

## 金额

| 过滤器 | 示例 | 作用 |
| - | - | - |
| `money` | `{{ total_price \| money }}` | 以分为单位的金额，按订单的币种显示 |
| `money_with_currency` | `{{ total_price \| money_with_currency }}` | 同上，并附带币种代码（`$1.00 USD`） |
| `money_without_currency` | `{{ total_price \| money_without_currency }}` | 仅显示数字（`1.00`） |
| `money_without_trailing_zeros` | `{{ 10000 \| money_without_trailing_zeros }}` | 省略 `.00`（`$100`） |
| `money_in` | `{{ amount \| money_in: 'EUR' }}` | 按您指定的币种显示金额 |

请参阅[模板中的金额和币种](https://foliant-help.iforiti.com/cn/template-editor/liquid-money-and-currency.md)。

## 日期和措辞

| 过滤器 | 示例 | 作用 |
| - | - | - |
| `date` | `{{ created_at \| date: '%d %B %Y' }}` | 格式化日期，月份和星期名称使用单据的语言。如需覆盖，请添加语言：`date: '%B', customer_locale`。 |
| `t`（也可用 `translate`、`label`） | `{{ 'subtotal' \| t }}` | 单据语言下的 Foliant 措辞 |
| `t_both` | `{{ 'titles.invoice' \| t_both }}` | 单据语言及其第二语言下的措辞（"Rechnung / Invoice"） |
| `labelled` | `{{ shop.vat_number \| labelled: 'vat_number', ' · ' }}` | 在标签后显示值（" · VAT number NL…"）；值为空时不显示任何内容 |

请参阅[日期、语言和翻译](https://foliant-help.iforiti.com/cn/template-editor/liquid-dates-and-languages.md)。

## 地址、图片和链接

| 过滤器 | 示例 | 作用 |
| - | - | - |
| `format_address` | `{{ shipping_address \| format_address }}` | 按 Shopify 的方式分行排列地址 |
| `img_url` | `{{ line_item.image \| img_url: '120x120' }}` | 指定尺寸的 Shopify 图片：`'thumb'`、`'small'`、`'medium'`、`'large'` 或 `'120x120'` |
| `img_tag` | `{{ line_item.image \| img_url: 'thumb' \| img_tag }}` | 为图片地址生成 `<img>` 标签。可选替代文本和类名：`img_tag: 'Logo', 'logo'` |
| `link_to` | `{{ 'Track your order' \| link_to: order_status_url }}` | 一个链接 |

## 条形码和二维码

| 过滤器 | 示例 | 作用 |
| - | - | - |
| `barcode` | `{{ line_item.sku \| barcode }}` | 条形码（默认为 Code 128，除非您指定类型，例如 `'ean13'`） |
| `qr` | `{{ order_status_url \| qr }}` | 二维码 |

请参阅[条形码和二维码](https://foliant-help.iforiti.com/cn/template-editor/liquid-barcodes-and-qr-codes.md)。

## 数字和文本

| 过滤器 | 示例 | 作用 |
| - | - | - |
| `weight_with_unit` | `{{ line_item.grams \| weight_with_unit }}` | 以克为单位的重量并附带单位：显示为克，达到 1,000 g 时显示为千克。指定单位即可换算：`weight_with_unit: 'lb'`（`kg`、`g`、`lb` 或 `oz`） |
| `format_number` | `{{ 1234.5 \| format_number: 2 }}` | 使用单据语言的分隔符显示数字（德语为 `1.234,50`） |
| `number_with_precision` | `{{ 1.2345 \| number_with_precision: 2 }}` | 保留指定位数小数的数字（`1.23`） |
| `pluralize` | `{{ item_count \| pluralize: 'item', 'items' }}` | 根据数量显示单数或复数形式的词 |
| `handleize` | `{{ 'Hello World!' \| handleize }}` | `hello-world` |
| `strip_html` | `{{ product.description \| strip_html }}` | 移除 HTML 标签 |
| `truncate_words` | `{{ product.description \| truncate_words: 20 }}` | 将文本缩短到指定的字数 |
| `default_value` | `{{ po_number \| default_value: 'N/A' }}` | 值为空时显示的备用内容 |
| `json` | `{{ shipping_address \| json }}` | 以数据形式显示值，方便您在制作模板时查看其中的内容 |

## 颜色

| 过滤器 | 示例 | 作用 |
| - | - | - |
| `color_mix` | `{{ shop_accent_color \| color_mix: '#ffffff', 20 }}` | 混合两种颜色：第一种颜色占 20% |
| `color_contrast` | `{{ shop_accent_color \| color_contrast: '#ffffff' }}` | 两种颜色之间的对比度（1–21） |

## 代码片段

有两个内置代码片段可打印标准的增值税部分：

* `{% include 'vat_breakdown' %}`：按税率列出的增值税明细表。
* `{% include 'legal_notes' %}`：增值税法律说明（反向征收、出口、IOSS…）。

请参阅[税务和法律](https://foliant-help.iforiti.com/cn/tax-and-legal.md)。

## 注意事项

* 代码编辑器会用警告标记它无法识别的过滤器。看到警告时，请检查预览。
* Shopify 店面主题中的部分过滤器在单据中不存在。请只使用上述过滤器和 Liquid 的标准过滤器。

## 相关文章

* [模板中的金额和币种](https://foliant-help.iforiti.com/cn/template-editor/liquid-money-and-currency.md)
* [日期、语言和翻译](https://foliant-help.iforiti.com/cn/template-editor/liquid-dates-and-languages.md)
* [条形码和二维码](https://foliant-help.iforiti.com/cn/template-editor/liquid-barcodes-and-qr-codes.md)
* [订单对象和常用变量](https://foliant-help.iforiti.com/cn/template-editor/liquid-order-variables.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.