3

I can successfully get entries related the "normal" way, but my list of possible results are getting quite large. Currently I am returning html mixed in with the data. It's obvious I need to get just the data and parse through it on the client side.

mytemplate.html

{% set paramOne = craft.request.getParam('paramOne') %}
{% set paramTwo = craft.request.getParam('paramTwo') %}

{% set relationParam = ['and'] %}

{% if paramOne %}
    {% set type = craft.categories.group('groupOne').slug(paramOne).first() %}
    {% set relationParam = relationParam|merge([{ targetElement: type }]) %}
{% endif %}

{% if paramTwo %}
    {% set type = craft.categories.group('groupTwo').slug(paramTwo).first() %}
    {% set relationParam = relationParam|merge([{ targetElement: type }]) %}
{% endif %}

{% set entries = craft.entries.relatedTo(relationParam) %}

I'm not quite sure how to translate that into elementapi code (for lack of better words).

elementapi.php

return [
    'endpoints' => [
        'myfile.json' => function (??) {
            $paramOne = craft()->request->getPost('paramOne');
            $paramTwo = craft()->request->getPost('paramTwo');

            return [
                'elementType' => 'Entry',
                'criteria' => [
                    'section' => 'mysection',
                    'relatedTo' => [
                        'and' // and needs to go somewhere...
                        'targetElement' => ??, // This is the entry
                        'field' => ?? // This is the category?
                    ],
                ],
                'transformer' => function (EntryModel $entry) {
                    return [
                        'title' => $entry->title
                    ];
                },
            ]
        }
    ]
];
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.