1

EE 5.2.2

I am making an app that lists channel entries in a template. Some of the data in these entries could be very substantial so I would like to only call that data if/when the user chooses. The way I would like to do this is by running an ajax query that will pass the id of that entry and return the requested field data for it.

Does EE have any helpful built-in functionality that can handle something like this? If not I'm assuming I will have to create a plugin action id to query the data using php.

Thank you.

1 Answer 1

1

There are answers both complex and simple, really depending on your actual use case.

This simple answer is just to AJAX in a template that does what you want. There is no reason you can't have a template that looks like this:

template: my_template_group/ajax_entry.html
accessed url: my_template_group/ajax_entry/100
template content:

{exp:channel:entries
    entry_id="{segment_3}"
    limit="1"}
    {if no_results}{redirect="404"}{/if}
    <div class="ajaxed-content">
        <h1>
            {title}
        </h1>
        <p>
            {my_custom_field}
        </p>
    </div>
{/exp:channel:entries}

And just AJAX that template in, then all of your logic will be in the JavaScript in your main listing template.

Now if you need something that is more akin to an API for Channel Entries, you are looking at crafting your own plugin/module. I can't tell if you specifically want to select certain fields to return or just need something simple. If your use case is small, you could just have 5 or so special templates like the one above and just AJAX the template you need when you need it.

And if you want, you can make a template return JSON or XML and consume the data that way if you need to do special stuff with it in JavaScript after it's been pulled in.

1
  • 1
    Is there any more documentation on the process you described? All I really want is to get a JSON object for one field for the channel entry when a link within its entry tag is clicked.
    – Shayne
    Commented Jun 17, 2019 at 19:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.