Background
EasyDocs is a document generation service designed to facilitate the creation of documents from custom templates.
Document Creation
Documents are generated by combining the following elements:
- Templates: Pre-defined layouts that structure the document.
- Data: JSON data to be used to populate template.
- Liquid: Utilized for parsing and dynamically rendering the data within the templates.
There are three Template types:
- Upload Template: Import an existing Word document to serve as a template.
- Dnd Template: Templates created using dnd editor.
- Html Template: Templates created using html editor.
Liquid
EasyDocs offers robust support for the Liquid Templating Language, a powerful and flexible open-source templating engine. This feature allows users to insert dynamic content into their document templates easily.
Dynamic Data Insertion
With Liquid syntax, you can dynamically insert variables into your document. For example, inserting a user's name would look like this:
Hello, {{ user.name }}
Data Manipulation
Liquid also provides a variety of filters to modify variable output. For instance, changing the case of a string can be done as follows:
{{ "hello world" | upcase }} <!-- Output: "HELLO WORLD" -->
Conditional Rendering
You can conditionally include or exclude parts of your document based on logic. The if
, elsif
, else
, and unless
tags allow for this:
{% if user.paid %}
Show premium content here.
{% else %}
Show free content here.
{% endif %}
Loops
Iterate over arrays or objects to populate lists or tables:
{% for item in items %}
{{ item.name }}: {{ item.price }}
{% endfor %}
Customization
Users can incorporate these Liquid functionalities directly into their templates, offering a high degree of customization and dynamic data rendering.
Parsing Process
When a Document is downloaded, EasyDocs parses the Liquid in the template, replacing placeholders and executing logic based on the provided data, to create the final, customized document.
Upload Templates
Table Parsing with Liquid Syntax
You can use this syntax within Word tables for dynamic rendering as well.
Name | Price | Quantity |
---|---|---|
{% for item in items %} {{ item.name }} | {{ item.price | currency }} | {{ item.quantity }} {% endfor %} |
This allows the Liquid engine to generate multiple table rows dynamically when parsing the XML string.
Example Result
Name | Price | Quantity |
---|---|---|
Pencil | $5.00 | 20 |
Book | $30.00 | 10 |
Desk | $100.00 | 1 |
Resources
Liquid Playground | Liquid playground where you can try play around with liquid. Playground provides a liquid editor and a data editor. |
Try Liquid | Another liquid playground for trying out liquid. This one comes with some prebuilt examples. |
Available Liquid Tags | List of all available liquid tags that can be used in you document templates. |
Available Liquid Filters | List of all available liquid filters that can be used in your document templates. (Note: The currency filter (as seen above) is a custom filter that we introduced for displaying currencies with a '$' and fixed to 2 decimal places) |