Lesson 6: Accessing an item directly

There are three ways to access a single item. Let's say you only want the first item from a set, you use the first() direct data call to access it. The other 2 direct data calls are: filter() and last()

Parsley Code Example (editable)
Run
Result

Content Collection Reference

The tabs below describe the Content Collections this Zesty.io REPL has access to. Content collections are created and edited in the Schema section of the Zesty.io Manager interface. You can configure any content collection with your own custom fields and views.


Example Page is a Content Collection in the Zesty.io REPL that was created in the Schema section. It has a template file (view) and routing behavior to represent a single page. This content collections has 8 fields on it, described below with their reference name and field type. When you make your own content set, you can add as many fields as you need. They can be accessed using either {{page.reference_name}} (when working on its related template file), or from any other template or JSON file by using {{example_data.first().reference_name}}

Collection Schema
Reference Name Type
title text
html wsywig
image image
multiple_images image
date date
dropdown dropdown
number number
Example Page Details

Friendly Name: Example Page

Reference Name: example_page

Has View: True

Routing Behavior: Single Page

Ways to Access with Parsley

There are many ways to access the content from a collection. The most common way is when you are working with it's associated template, when you are, content can be accessed like:

  • {{this.title}}
  • {{this.description}}
  • {{this.html}}
  • {{this.image}}
  • {{this.multiple_images}}
  • {{this.date}}
  • {{this.dropdown}}
  • {{this.number}}

Another way is with global access calls, which look this:

  • {{example_data.first().title}}
  • {{example_data.first().description}}
  • {{example_data.first().html}}
  • {{example_data.first().image}}
  • {{example_data.first().multiple_images}}
  • {{example_data.first().date}}
  • {{example_data.first().dropdown}}
  • {{example_data.first().number}}

Slides are a content collection that do not have a behavior for routing or view file, this type of collection is. When created, it was given the reference name "example_data". The reference name is used to access content associated on that collection. This content set has 8 fields on it, described below with their reference name and field type. When you make your own content set, you can add as many fields as you need. They can be accessed using either {{thispage.reference_name}} (when working on a its related template file), or from any other template or JSON file by using {{example_data.first().reference_name}}

Slides are a content collection that do not have a behavior for routing or view file, this type of collection is. W

Content Collection

A Content Collection, Collection for short, is a data store that is configurable to match its use case (e.g. contact page, blog article, employees references, homepage content, etc.). Once is a collection is made, any user with content editing access in that Zesty.io instance can create and modify content. Collections may be standalone (headless) and/or can be associated to a template with routing for websites (www functionality).

Field

Fields are editable content areas on a content collection. 

Hugs

Hugs, or french brackets, curly brackets, or mustaches, you name it, they are the characters that wrap Parsley code which tells the parser to render the content Parsley is asking for.

Reference Name

This is a unique identifier of a field on a content collection. The reference name is used in Parsley to allow developers to access content in their templates.

REPL

A Read–Eval–Print Loop (REPL), also known as an interactive toplevel or language shell, is a simple, interactive computer programming environment that takes single user inputs (i.e. single expressions), evaluates them, and returns the result to the user; a program written in a REPL environment is executed piecewise.

Schema

Schema is a section of the Zesty.io content manager interface. From schema users can create and edit content collections.