{% extends "forms/fields/input/selectize.html.twig" %}

{% block global_attributes %}
    {% set post_type = field.post_type|default('page') %}
    {% set post_status = field.post_status|default('publish') %}
    {% set posts_per_page = field.posts_per_page|default('-1') %}
    {% set orderby = field.orderby|default('title') %}
    {% set order = field.order|default('asc') %}
    {% set array = {
        'post_type': post_type,
        'post_status': post_status,
        'posts_per_page': posts_per_page,
        'orderby': orderby,
        'order': order,
    } %}
    {% set posts = gantry.platform.call('Timber::get_posts', array) %}
    {% set Options = field.selectize.Options %}
    {% set options = [] %}
        {% for id,post in posts %}
            {% set id = post.id %}
            {% set options = options|merge([{value: id, text: post.post_title}])  %}
        {% endfor %}

        {% set field = field|merge(field.selectize.Options|default({}))|merge({selectize: { Options: options, create: false }}) %}
    {{ parent() }}
{% endblock %}
