Flex Directory

getTitle()

getTitle(): string Get title of the directory

Returns:

  • string Title
{% set directory = grav.get('flex').directory('contacts') %}

<h2>{{ directory.title|e }}</h2>

getDescription()

getDescription(): string Get description of directory

Returns:

  • string Description
{% set directory = grav.get('flex').directory('contacts') %}

<p>{{ directory.description|e }}</p>

getObject()

getObject( id ): Object | null Get an object, returns null if it was not found.

Parameters:

  • id ID of the object (string)

Returns:

  • Object (object)
  • null Object not found
{% set directory = grav.get('flex').directory('contacts') %}

{% set contact = directory.object('ki2ts4cbivggmtlj') %}

{# Do something #}
{% if contact %}
  {# Got Bruce Day #}
  Email for {{ contact.first_name|e }} {{ contact.last_name|e }} is {{ contact.email|e }}
{% else %}
  Oops, contact has been removed!
{% endif %}

Check what you can do with Flex Object

getCollection()

getCollection(): Collection Get collection, returns null if it was not found.

Returns:

{% set directory = grav.get('flex').directory('contacts') %}

{% set contacts = directory.collection() %}

{# Do something #}
<h2>Ten first contacts:</h2>
<ul>
  {% for contact in contacts.filterBy({published: true}).limit(0, 10) %}
    <li>{{ contact.first_name|e }} {{ contact.last_name|e }}</li>
  {% endfor %}
</ul>

Check what you can do with Flex Collection

Found errors? Think you can improve this documentation? Simply click the Edit link at the top of the page, and then the icon on Github to make your changes.