Decode json file {cache_remote_file}

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
andrewvideouk
Forum Members
Forum Members
Posts: 155
Joined: Thu Aug 20, 2020 10:49 pm

Decode json file {cache_remote_file}

Post by andrewvideouk »

Hi Guys.

I am trying to Decode json file using cache_remote_file plugin. I cant get my head round how to do this. This is my attempt and cant workout how to do this. Can please someone tell me what I am doing worng and how to it. Thank you.

Code: Select all

{capture assign=feed}{cache_remote_file url="https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&id=Duf5UUT......"}{/capture}


{foreach from=$feed|json_decode item=data}
           <p> title : {$data->items->snippet->title}  </p>
            <p> img : {$data->items->snippet->thumbnails->default->url}  </p>
      
{/foreach}

Code: Select all

{
  "kind": "youtube#videoListResponse",
  "etag": "9ZzDWJlUMjKGsGwGvtEREF_adhk",
  "items": [
    {
      "kind": "youtube#video",
      "etag": "L3XeWemLM2vSCJh_RkWQgIjUbs4",
      "id": "Duf5UUT4ESg",
      "snippet": {
        "publishedAt": "2021-07-21T16:39:22Z",
        "channelId": "UCEUfZ0aVKoC80RIAfvTBfDw",
        "title": "Sheffield Voices speaking out on issues of abuse at Firshill Sheffield",
        "description": "Sheffield Voices Self Advocacy group have been shocked and upset by reports of people with learning disabilities and Autism being restrained, not being given food and water, being ignored and not being protected from violence within the Assessment and Treatment Unit and have made a video so people know how we are feeling about this",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/Duf5UUT4ESg/default.jpg",
            "width": 120,
            "height": 90
          },
          ......................
andrewvideouk
Forum Members
Forum Members
Posts: 155
Joined: Thu Aug 20, 2020 10:49 pm

Re: Decode json file {cache_remote_file}

Post by andrewvideouk »

I was missing the [0] which I didn't know. I was so close. Now it working.

{foreach from=$feed|json_decode item=data}
<p> title : {$data[0]->snippet->title} </p>
<p> img : {$data[0]->snippet->thumbnails->default->url} </p>
{/foreach}
andrewvideouk
Forum Members
Forum Members
Posts: 155
Joined: Thu Aug 20, 2020 10:49 pm

Re: Decode json file {cache_remote_file}

Post by andrewvideouk »

I thought I got that working. Do anyone how do this? Cheers
macyogi2
New Member
New Member
Posts: 1
Joined: Mon Oct 04, 2021 9:44 am

Re: Decode json file {cache_remote_file}

Post by macyogi2 »

Hi,
I do not know the cache_remote_file plugin.
However, based on the JSON, I would suggest the following code:

Code: Select all

{capture assign=feed} ... {/capture}

{$feed = $feed|json_decode}
{foreach from=$feed->items item=item}

           <p> title : {$item->snippet->title}  </p>
            <p> img : {$item->snippet->thumbnails->default->url}  </p>
      
{/foreach}
best wishes
andrewvideouk
Forum Members
Forum Members
Posts: 155
Joined: Thu Aug 20, 2020 10:49 pm

Re: Decode json file {cache_remote_file}

Post by andrewvideouk »

Thank you so much. That worked great.
Post Reply

Return to “Modules/Add-Ons”