EEConf 2024 is around the corner! EEConf 2024
I am not a php developer so I can’t really save a template as php and do php code. I am not sure what the REQUEST function does and if that is a solution. This is a new site and I am using EE7. If I need to make a simple call to get info via a REST GET on a product ID and want to parse it in my template, what is the best way to do this?
Hello!
I have been using an old json plugin that was designed for EE version 3. So far it has been working very well on EE Version 7
https://github.com/ahmmadsaleh86/Json-Plugin (After downloading, you need to put the plugin files in the correct folder structure for the newer versions of EE:)
/system/user/addons/json/pi.json.php
/system/user/addons/json/addon.setup.php
Here is a quick example of how I am using it:
My remote JSON Data - via a public GET URL/endpoint:
{
"ref": "14300",
"field12": "1993-02-23 00:00",
"field8": "title content in here",
"field10": "the author",
"field3": "",
"order_by": "50",
"total_hit_count": "1844"
},
EE Template Code:
{exp:json ref='https://myremoteapiurlhere/api/collection_recent/153/' fields="ref field8 field10 field12" limit="6"}
<div class="col-lg-2 col-sm-6 sm-mb-30">
<div class="about-mission-box white-bg h-100">
<a href="/resources/pages/view.php?ref={ref}">_ <div class="content">_ <h6>{field8}</h6>_ <?php $date='{field12}'; if ($date) { echo date("F j, Y", strtotime($date)); } ?>_ </div>_ </a>
</div>
</div>
{/exp:json}
Note how you tell the plugin which key-value pairs to fetch from the payload, you then use those as variables in your code which is really handy! I enabled PHP in my template so I could modify the date to suit my needs.
Template caching helps with performance if you need to parse and render many items.
A newer, more advanced json plugin is also available. I haven’t had any personal experience with it yet.
https://devot-ee.com/add-ons/ee-json-output (I haven’t had any experience with it yet)
Best Regards,
Brian
If you are using ExpressionEngine 7 and want to make a REST GET request to retrieve information on the product ID and parse that information in your template, you can consider using the ExpressionEngine add-on, check if there are any existing EE7 compatible add-ons that support making REST API calls. The ExpressionEngine community and the official add-ons directory bitlife are good places to start looking.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.