@directus-labs/liquidjs-operation

中文文档
1.2.0发布于 2025/05/29MITES Module近 30 天下载 2183

Render Liquid templates within Directus flows.

原始使用文档
文档目录16 节
  1. Features
  2. Configuration Options
  3. Template Mode
  4. Operation Mode
  5. Template
  6. Collection
  7. Template Item
  8. Fields to Render
  9. Data
  10. Access Token
  11. Public URL
  12. Data Fields to Return
  13. Samples
  14. Single Mode Example
  15. Batch Mode Example
  16. Security Considerations

Liquid Template Operation

Liquid Template Operation

The Liquid Template Rendering Operation allows you to dynamically generate content using the powerful LiquidJS templating language. This operation is perfect for creating personalized emails, generating dynamic content, or any scenario where you need to combine data with templates within a flow.

Features

  • Support for both custom and saved templates
  • Single and batch processing modes
  • Ability to return specific fields from the input data alongside rendered content
  • Secure template fetching with optional authentication

Important Note: This extension uses custom delimiters for output tags {# #} instead of the original {{ }} . This is to avoid conflicts with the mustache syntax that Directus uses to populate values from other steps inside a Flow.


Configuration Options

Sample Saved Template Configuration Sample Saved Template Configuration

Sample Custom Template Configuration Sample Custom Template Configuration

Template Mode

Choose how to provide the Liquid template:

  • Custom: Write the template inline within the operation.
  • Saved: Use a template stored in a Directus collection.

Operation Mode

Select the processing mode:

  • Single: Render one template with a single data object.
  • Batch: Render the template multiple times, once for each item in an array of data objects.

Template

  • (Custom Mode Only)

Enter your Liquid template here. Use {# #} for output tags instead of {{ }}. All other Liquid tags remain unchanged.

Example: Hello, {# user.name #}! {% if user.admin %}Admin area{% endif %}

Collection

  • (Saved Mode Only)

Select the collection containing your saved Liquid templates.

Template Item

  • (Saved Mode Only)

Choose the specific template to render from the selected collection.

Fields to Render

  • (Saved Mode Only)

Select the fields from the template item to include in the rendering process.

Data

JSON data to populate the template. Format: object for single mode, array of objects for batch mode. Supports mustache syntax for dynamic values, e.g., {"user": "{{$trigger.user}}"}

Access Token

  • (Saved Mode Only)

Required for accessing private template collections. Ensure the token has read permissions for the template collection.

Public URL

The public URL of your Directus instance. Used for fetching saved templates.

Data Fields to Return

  • (Batch Mode Only)

Choose fields from your input data to include in each output object. Useful for maintaining context or identification (e.g., "id", "name"). These fields will be added alongside the rendered template for each item in batch mode.


Samples

Single Mode Example

  • Template Mode: Custom
  • Operation Mode: Single

Template

<div>
<p>Hi {# first_name #}!</p>
<p><strong>Thanks for registering for XYZ!</strong></p>
<p>Here's your confirmation code:</p>
<pre>{# confirmation_code #}</pre> p
<p><strong><a href="https://yoururlhere.com/t/{# ticket.slug #}" target="_blank" rel="noopener">Your Ticket</a></strong></p>
<hr>
<p>The Team</p>
</div>

Data

{
    "first_name": "Bryant",
    "confirmation_code": "ABCDEFG",
    "ticket": {
        "slug": "test"
    }
}

Output

{
  "template": "<div>\n<p>Hi Bryant!</p>\n<p><strong>Thanks for registering for XYZ!</strong></p>\n<p>Here's your confirmation code:</p>\n<pre>ABCDEFG</pre> p\n<p><strong><a href=\"https://yoururlhere.com/t/test\" target=\"_blank\" rel=\"noopener\">Your Ticket</a></strong></p>\n<hr>\n<p>The Team</p>\n</div>"
}

Batch Mode Example

  • Template Mode: Custom
  • Operation Mode: Batch
  • Return Fields From Data: [”first_name”]

Template

<div>
<p>Hi {# first_name #}!</p>
<p><strong>Thanks for registering for XYZ!</strong></p>
<p>Here's your confirmation code:</p>
<pre>{# confirmation_code #}</pre> p
<p><strong><a href="https://yoururlhere.com/t/{# ticket.slug #}" target="_blank" rel="noopener">Your Ticket</a></strong></p>
<hr>
<p>The Team</p>
</div>

Data

[
    {
        "first_name": "Bryant",
        "confirmation_code": "ABCDEFG",
        "ticket": {
            "slug": "test"
        }
    },
    {
        "first_name": "John",
        "confirmation_code": "HIJKLM",
        "ticket": {
            "slug": "test"
        }
    }
]

Output

[
  {
    "first_name": "Bryant",
    "template": "<div>\n<p>Hi Bryant!</p>\n<p><strong>Thanks for registering for XYZ!</strong></p>\n<p>Here's your confirmation code:</p>\n<pre>ABCDEFG</pre> p\n<p><strong><a href=\"https://yoururlhere.com/t/test\" target=\"_blank\" rel=\"noopener\">Your Ticket</a></strong></p>\n<hr>\n<p>The Team</p>\n</div>"
  },
  {
    "first_name": "John",
    "template": "<div>\n<p>Hi John!</p>\n<p><strong>Thanks for registering for XYZ!</strong></p>\n<p>Here's your confirmation code:</p>\n<pre>HIJKLM</pre> p\n<p><strong><a href=\"https://yoururlhere.com/t/test\" target=\"_blank\" rel=\"noopener\">Your Ticket</a></strong></p>\n<hr>\n<p>The Team</p>\n</div>"
  }
]

Security Considerations

  • When using saved templates, ensure that the access token has the minimum necessary permissions.
  • Be cautious when using user-provided data in templates to avoid potential security risks.
  • Consider using Directus roles and permissions to control access to sensitive templates or data.

版本与发布记录

@directus-labs/liquidjs-operation 共发布 4 个版本,首次发布于 2024/08/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.0latest2025/05/291.5 年前
1.1.02025/02/101.8 年前
1.0.12024/08/302 年前
1.0.02024/08/302 年前

关于 @directus-labs/liquidjs-operation 的常见问题

@directus-labs/liquidjs-operation 是什么?

Render Liquid templates within Directus flows.

如何安装 @directus-labs/liquidjs-operation?

在项目目录运行 npm install @directus-labs/liquidjs-operation,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:liquidjs(10.20.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@directus-labs/liquidjs-operation 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/directus-labs__liquidjs-operation 是否存在。

@directus-labs/liquidjs-operation 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@directus-labs/liquidjs-operation 可以商用吗?

@directus-labs/liquidjs-operation 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@directus-labs/liquidjs-operation 的下载量有多少?

根据 npm 官方下载统计,@directus-labs/liquidjs-operation 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,183 次,日均约 73 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@directus-labs/liquidjs-operation 还在维护吗?

最新版本 1.2.0 发布于 2025/05/29(1.5 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/08/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。