Parsley December 2022 Release

New functionality for JSON, arrays, relationships, and shorthand syntax

Parsley December 2022 Release

Randy Apuzzo 12.07.2022

Parsley Header

Parsley recently underwent a large update, adding major features while supporting all previous usages. The goals of this update were threefold:

  • Remove barriers for developers to make it easier to access content relationships

  • Create JSON endpoints

  • Tighten up code lines

JSON as Content Iteration and Access Support

Zesty has supported outputting JSON and accepting JSON with our APIs, but we have not commonly seen JSON stored as content in the system. Now we provide Parsely support when JSON is stored as content.

JSON Content Iteration

JSON stored in a content model field can be iterated by using parsley, the same as content items.

Preview a live JSON iteration example here: https://parsley.zesty.io/iterating-over-a-content-stored-json-object-with-an-array/

<ul>
   {{each {this.json_object}.json(arr) as item}}
   <li>{{item.title}}</li>
   {{end-each}}
</ul>

Accessing Objects in JSON

Quickly access an object of an object to access its value.

Live example: https://parsley.zesty.io/accessing-a-json-object-within-an-object/

{{this.json_object.json(obj_within.name)}}

Iterating String Arrays

This refers to support for objects that store arrays of strings without keys.

Live example: https://parsley.zesty.io/iterating-through-a-json-array-of-strings/

{<ul>
{{each {this.json_object}.json(arr_strings) as item}} 
       <li>{{item._string}}</li>
{{/each}}
</ul>

Each Statement Updates

Each statement's code gets reduced with shortcut statements and easier iteration of content relationships.

Content Relationship Iteration 

Before, making content relationships in parsley required the following code to form the relationship.

Old Style

{{each tags as tag where find_in_set(z.zuid,'{article.tags}')}}

<a href="{{tag.getURL()}}">{{tag.name}}</a>

{{end-each}}

The latest update simplifies the logic and reduces code length by allowing the relationship to be directly referenced in each loop. It also provides a shortened end-each option.

New Style https://parsley.zesty.io/iterate-through-a-model-relationship-field/

{{each {article.tags} as tag}}

<a href="{{tag.getURL()}}">{{tag.name}}</a>

{{/each}}

Array Commas

Outputting custom JSON data endpoints with Parsley content syntax requires extra logic if you are outputting an array of objects. This update streamlines that logic. Here is what use to look like to output 10 random articles to JSON.

Old Style

[

{{each articles as article limit 10 order by rand() }}

   {{article.toJSON()}}

  {{if {article._num} < {article._length} }},{{end-if}}

{{end-each}}

]

Note the logic does not have a trailing comma. That is what we replace with _arraycomma. _arraycomma will always know the last item in your array and will not put a comma after the last value. Otherwise, a comma will be appended after each value.

New Style https://parsley.zesty.io/generate-json-output/

[

{{each articles as article limit 10 order by rand() }}

   {{article.toJSON()}} {{article._arraycomma}}

{{/each}}

]

Ending Each Iterations and If Logic Statements

A simple change to shorten code for an each statement {{end-each}} can now be written as {{endeach}} or {{/each}}.

If statements can now be terminated with {{/if}}, {{endif}} or {{end-if}}

Data Access Calls

Data access calls are streamlined and gain two new functions.

Live examples https://parsley.zesty.io/directly-access-an-item-of-a-content-model-by-zuid/

Previous way to access a single item with parsley content syntax:

Old Style 

{{articles.filter(z.zuid = '{this.articlezuid}').title}}

New Style

{{articles.filter({this.articlezuid}).title}}

Using filter to search

{{articles.filter(title like '%parsley%').title}}

Example of a custom JSON endpoint to get a single item outputted to a fully hydrated JSON object. Make a custom file in code, /data/article.json with code

{{articles.filter({request.queryParam(zuid)}).toJSON()}}

Then call the endpoint with a ZUID www.domain.com/data/article.json?zuid=7-x1y2z3-x1y2z3

 

Have Parsley Ideas?

We are open to hearing your ideas and may incorporate them in the next release. Contact your customer service manager to provide feedback.

Experience a Headless Content Management System, Join Zesty.io.


Start a Sandbox Now

More from Mindshare:

Placeholder image

Upcoming Change to Supported TLS Ciphers

Notice of scheduled removal of supported TLS cipher suites

Read Article
Placeholder image

First-Party Cookies vs Third-Party Cookies: Explaining the Cookie Trend

Marketers will have to change their advertising strategies since the use of cookies will dramatically change.

Read Article
Placeholder image

Choosing a DXP: Non-technical Considerations

When deciding on a DXP, make sure to consider factors outside of the platform itself, including how your team and

Read Article
Placeholder image

Zesty single sign-on: everything you need to know

Zesty recently released single sign-on (SSO) capabilities. This article addresses common questions.

Read Article
Randy Apuzzo photo

Randy Apuzzo

Founder & CEO, Zesty.io

Randy has had a penchant for computer programming from an early age and started applying his skills to build business software in 2004. Randy's stack of skills range from programming, system architecture, business know-how, to typographic design; which lends to a truly customer-centric and business effective software design. He leads... Learn More

Exploring content solutions? Looking to replatform?