npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@directus-labs/liquidjs-operation

v1.0.1

Published

Render Liquid templates within Directus flows.

Downloads

196

Readme

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.