A
A
Alexey2020-05-22 11:49:14
PHP
Alexey, 2020-05-22 11:49:14

How to customize output in array template?

The idea is this:
There is a page on it, a post request is made to search in ajax.php, which sends a request to an external API and receives an array
Ajax.php code:

$url = 'http://domen.ru/api/search.php';
$params = array(
    'search' => $_POST['search'],
    'key' => $secret_key,
);
$result = file_get_contents($url, false, stream_context_create(array(
    'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query($params)
    )
)));
$result = json_decode($result, true);

Further in this ajax.php check for $result and output (which I can't get):
if ($result) {
    foreach ($result as $key => $value) {
        $id = $value['id'];
        $date = $value['date'];
        $title = $value['title'];
        $thumb = $value['thumb'];
        include '../tpl/remotePostSearch.tpl';
    }
}


Accordingly, the whole idea is to pass a two-dimensional array (for example):
Array
(
    [0] => Array
        (
            [title] => Кофе
            [date] => 30/04/2020
            [id] => 5
            [thumb] => /32894e4b.jpg
        )

    [1] => Array
        (
            [title] => Чай
            [date] => 30/04/2020
            [id] => 4
            [thumb] => 1528900394_clash-of-clans.png
        )

)

into the template and display it in a normal view through the .tpl template:
<h2><?=$title?></h2>
<div>
<img src="http://domen.ru/images/<?=$thumb?>">
<p><?=$id?> :: <?=$date?></p>
</div>


But it turns out that it is not clear.
Where is the jamb and how to implement such a conclusion?
ajax.php on the output should generate html code based on the tpl file

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question