Skip to content

Instantly share code, notes, and snippets.

@Sogl
Last active September 4, 2022 20:03
Show Gist options
  • Save Sogl/e70b949da2e951f540a68d8cc66b584d to your computer and use it in GitHub Desktop.
Save Sogl/e70b949da2e951f540a68d8cc66b584d to your computer and use it in GitHub Desktop.
Contacts Flex example (Grav CMS)
{# flex/contacts/collection/default.html.twig #}
{{ dump(page.url) }}
{%- set object_context = object ?? {} -%}
{%- set object_layout = object_context.layout ?? ('list-' ~ layout) -%}
<div id="flex-objects">
<div class="text-center">
<input class="form-input search" type="text" placeholder="Поиск по имени, е-мейл итд" />
<button class="button button-primary sort asc" data-sort="name">
Сортировать по имени
</button>
</div>
<ul class="list">
{% for object in collection.filterBy({ published: true }) %}
<li>
{% render object layout: object_layout with object_context %}
</li>
{% endfor %}
</ul>
</div>
<script>
var options = {
valueNames: [ 'name', 'email', 'website', 'entry-extra' ]
};
var flexList = new List('flex-objects', options);
</script>
{# flex/contacts/object/default.html.twig #}
{{ dump(url) }}
<div class="entry-details">
{% if object.website %}
<a href="{{ object.website|e }}"><span class="name">{{ object.last_name|e }}, {{ object.first_name|e }}</span></a>
{% else %}
<span class="name">{{ object.last_name|e }}, {{ object.first_name|e }}</span>
{% endif %}
{% if object.email %}
<p><a href="mailto:{{ object.email|e }}" class="email">{{ object.email|e }}</a></p>
{% endif %}
</div>
<div class="entry-extra">
{% for tag in object.tags %}
<span>{{ tag|e }}</span>
{% endfor %}
<span>ONE</span>
</div>
{# flex-objects/views/directory.html.twig #}
{{ dump(page.url) }}
{{ dump(options) }}
{% set flex = grav.get('flex_objects') %}
{% set directory = flex.directory(type) %}
{% if directory %}
{% set layout = options.layout ?? 'default' %}
{% set context = options ?? {} %}
{% set type = directory.flexType() %}
{% set collection = directory.collection %}
{%- set title = options.title -%}
{%- if title matches '/\{/' -%}
{%- set title = include(template_from_string(title, 'collection title template'))|trim -%}
{%- endif -%}
{% if title %}
{% do page.title(title) %}
{% endif %}
{% set tag = [] %}
{% set tag = uri.param('tag') ? tag|merge([uri.param('tag')]) : tag %}
{% if tag %}
{% set collection = collection.inArray('tags', tag) %}
{% endif %}
{% render collection layout: layout with {context_variable: true, title: title, url: page.url} %}
{% else %}
{% include 'flex-objects/views/404.html.twig' %}
{% endif %}
{# flex/contacts/object/list-default.html.twig #}
{{ dump(url) }}
<div class="entry-details">
<a href="{{ grav.uri.uri }}/id:{{ object.key }}"><span class="name">{{ object.last_name|e }}, {{ object.first_name|e }}</span></a>
{% if object.email %}
<p><a href="mailto:{{ object.email|e }}" class="email">{{ object.email|e }}</a></p>
{% endif %}
</div>
<div class="entry-extra">
{% for tag in object.tags %}
<span>{{ tag|e }}</span>
{% endfor %}
<span>LIST VIEW</span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment