Answer the question
In order to leave comments, you need to log in
How to insert php code into the page in october CMS?
There is a site on october.cms with one single page default.html
I know that in the "code" section I need to write php somehow sideways so that it works and displays the result with a tag like {{blabla} } But I'm so stupid that I don't know how it's right do. I ask for your help!
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://coingecko.p.rapidapi.com/exchanges/bamboo_relay/tickers",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"x-rapidapi-host: coingecko.p.rapidapi.com",
"x-rapidapi-key: 6ffd1d2182msh846abeb6f107c2cp15e4c8jsn66196e744cac"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
function print_arr($arr){
echo '<pre> ' . print_r($arr, true) . ' </pre>';
}
$infa = json_decode($response, true);
//zrx/weth para
$search;
foreach ($infa['tickers'] as $val) {
if ($val['base'] == 'ZRX' && $val['target'] == 'WETH') {
$search = $val;
break;
}
}
$zwbase = $search['base'];
$zwtarget = $search['target'];
$zwprice = $search['converted_last']['usd'];
$zwspread = $search['bid_ask_spread_percentage'];
$zwvolume = $search['converted_volume']['usd'];
$zwsp = number_format($zwspread, 2);
$zwvola = number_format($zwvolume, 0, '', ',');
//weth/usdc para
$search2;
foreach ($infa['tickers'] as $val2) {
if ($val2['base'] == 'WETH' && $val2['target'] == 'USDC') {
$search2 = $val2;
break;
}
}
$wubase = $search2['base'];
$wutarget = $search2['target'];
$wuprice = $search2['converted_last']['usd'];
$wuspread = $search2['bid_ask_spread_percentage'];
$wuvolume = $search2['converted_volume']['usd'];
$wusp = number_format($wuspread, 2);
$wuvola = number_format($wuvolume, 0, '', ',');
//dai/usdc para
$search3;
foreach ($infa['tickers'] as $val3) {
if ($val3['base'] == 'DAI' && $val3['target'] == 'USDC') {
$search3 = $val3;
break;
}
}
$dubase = $search3['base'];
$dutarget = $search3['target'];
$duprice = $search3['converted_last']['usd'];
$duspread = $search3['bid_ask_spread_percentage'];
$duvolume = $search3['converted_volume']['usd'];
$dusp = number_format($duspread, 2);
$duvola = number_format($duvolume, 0, '', ',');
//weth/dai para
$search4;
foreach ($infa['tickers'] as $val4) {
if ($val4['base'] == 'WETH' && $val4['target'] == 'DAI') {
$search4 = $val4;
break;
}
}
$wdbase = $search4['base'];
$wdtarget = $search4['target'];
$wdprice = $search4['converted_last']['usd'];
$wdspread = $search4['bid_ask_spread_percentage'];
$wdvolume = $search4['converted_volume']['usd'];
$wdsp = number_format($wdspread, 2);
$wdvola = number_format($wdvolume, 0, '', ',');
$infatxt="
<tr data-pair-code='usdteur' onclick=\"javascript:document.location.href='http://trade.reyna2.com:3001/#/erc20/?base=zrx"e=weth'\">
<td class='-name'><a>$zwbase/$zwtarget</a></td>
<td class='-price'><span>$$zwprice</span></td>
<td class='-change -down'><span>$zwsp%</span></td>
<td class='-volume'><span>$$zwvola</span></td>
</tr>
<tr data-pair-code='usdteur' onclick=\"javascript:document.location.href='http://trade.reyna2.com:3001/#/erc20/?base=weth"e=usdc'\">
<td class='-name'><a>$wubase/$wutarget</a></td>
<td class='-price'><span>$$wuprice</span></td>
<td class='-change -down'><span>$wusp%</span></td>
<td class='-volume'><span>$$wuvola</span></td>
</tr>
<tr data-pair-code='usdteur' onclick=\"javascript:document.location.href='http://trade.reyna2.com:3001/#/erc20/?base=dai"e=usdc'\">
<td class='-name'><a>$dubase/$dutarget</a></td>
<td class='-price'><span>$$duprice</span></td>
<td class='-change -down'><span>$dusp%</span></td>
<td class='-volume'><span>$$duvola</span></td>
</tr>
<tr data-pair-code='usdteur' onclick=\"javascript:document.location.href='http://trade.reyna2.com:3001/#/erc20/?base=dai"e=weth'\">
<td class='-name'><a>$wdbase/$wdtarget</a></td>
<td class='-price'><span>$$wdprice</span></td>
<td class='-change -down'><span>$wdsp%</span></td>
<td class='-volume'><span>$$wdvola</span></td>
</tr>
";
echo $infatxt;
?>
Answer the question
In order to leave comments, you need to log in
https://octobercms.com/docs/cms/pages#dynamic-pages
the code is put into the onStart() function, and what needs to be displayed is assigned to some $this field and then displayed in the markup. Better, of course, not as in the spaghetti given in the question, but to collect a normal array with data and walk through it in the output using the Twig loop.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question