Edit in GitHubLog an issue

Fragments

Fragments are special tags which enables users to write a composition using text tags or other fragments. Fragments introduce re-usability among the tags and enable users to create multiple such compositions and use them in their templates.

How to use ?#

To use fragments in the api, user will need to create a fragments json and pass it as a parameter in the api request body or they can use SDKs as well.

Below is a json defining fragments related to an address and a name use-case.

Copied to your clipboard
1{
2 "addressDetails" : "<br>{{streetDetails}}<br>{{localityDetails}}",
3 "streetDetails":"<span style=\"color: 0000FF;\">{{addressline1}}<br>{{addressline2}}<br>{{addressline3}}",
4 "localityDetails" : "<span style=\"color: 006400;\">{{city}},<i>{{state}}</i>-<b>{{pincode}}</b>",
5 "fullname": "<span style=\"color: ff0000;\">{{firstname}} {{lastnameStyled}}",
6 "lastnameStyled": "<span STYLE=\"font-size:14mm\"><b><i>{{lastname}}</i></b>"
7}

In the above json, we have defined fragments named addressDetails, streetDetails, localityDetails related to the address use-case and, fullname and lastnameStyled for the name use-case. Below is the explanation of the fragments defined above:

The addressDetails fragment composes streetDetails and localityDetails fragment tags.

The streetDetails fragment composes addressline1, addressline2 and addressline3 text tags.

The localityDetails fragment composes state, city and pincode text tags.

The fullname fragment composes firstname text tag and a lastnameStyled fragment tag.

The lastnameStyled fragment composes lastname text tag.

To resolve the text tags used in the above fragments, the jsonDataForMerge json would be:

Copied to your clipboard
1{
2 "addressline1": "Sample Address Line 1",
3 "addressline2": "Sample Address Line 2",
4 "addressline3": "Sample Address Line 3",
5 "city": "Sample City",
6 "state": "Sample State",
7 "pincode": "42132xx",
8 "firstname": "John",
9 "lastname": "Roy"
10}

There is one more way to define fragments json which can be used to organize related fragments together and separate unrelated fragments into another object, then all such objects can be combined in a json array.

Copied to your clipboard
1[
2 {
3 "addressDetails": "<br>{{streetDetails}}<br>{{localityDetails}}",
4 "streetDetails": "<span style=\"color: 0000FF;\">{{addressline1}}<br>{{addressline2}}<br>{{addressline3}}",
5 "localityDetails": "<span style=\"color: 006400;\">{{city}},<i>{{state}}</i>-<b>{{pincode}}</b>"
6 },
7 {
8 "fullname": "<span style=\"color: ff0000;\">{{firstname}} {{lastnameStyled}}",
9 "lastnameStyled": "<span STYLE=\"font-size:14mm\"><b><i>{{lastname}}</i></b>"
10 }
11]

In the above json array, first json object corresponds to the address related fragments and second for name related fragments

Below are the sample input and output documents snapshots describing the use of fragments.

Here the addressDetails fragment is used in the word document template file.

Address Input fragment

The output document generated will look like:

Output of address fragment in document

Similarly, the fullname fragment can be used like this in the word document template file.

Name Input fragment

And the output document generated will look like:

Output of name fragment in document

Limitations#

  • The Expressions and Jsonata functions are not supported inside the fragment definition.
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.