10 lis 2017

Odczyt atrybutów elementu w obsłudze zdarzena w javascript

<select name="banner_url" onchange="var idx=this.selectedIndex; 
var value=this.options[idx].getAttribute('banner_url'); 
var element = document.getElementById('img_banner_url'); 
element.setAttribute('src', value); element.style.display='block'">

!{section name=ii loop=$data}!
	!{capture assign=banner_url}!http://kody.wig.pl/!{/capture}!
	<option value="!{$banner_url}!" banner_url="!{$banner_url}!">
	!{$data[ii].name}! ---> !{$banner_url}!</option>
!{/section}!

</select>
<br><br>

<img decoding="async" src="" id="img_banner_url" style="display:none">
10 lis 2017

Przygotowanie odpowiedzi na zapytanie w ajax

require_once('config.php');
$data_js = '{"count":'.$cnt.', "data": '.json_encode($data_js).', "request":'.
json_encode($_GET).'}';

header('Content-type: application/json; charset='.$config['encoding']);
echo $data_js;
exit();
10 lis 2017

Przykład uruchomienia smartów

require_once('/app/config.php');
require_once('/app/smarty-3.1.29/libs/Smarty.class.php');

$smarty=new Smarty;
$smarty->template_dir = '/app/templates/';
$smarty->compile_dir = '/app/data/smarty/templates_c/';
$smarty->cache_dir = '/app/data/smarty/cache/';
$smarty->config_dir = '/app/data/smarty/config/';
$smarty->caching= false;
$smarty->force_compile=true;
//$smarty->force_compile=false;
$smarty->configLoad('pl.conf', 'index');
$smarty->left_delimiter = '!{';
$smarty->right_delimiter = '}!';

$data_to_send=$smarty->fetch('index.html');

header("Connection: close");
ignore_user_abort(true);
header('Content-type: text/html; charset='.$config['encoding']);
header("Content-Length: ".mb_strlen($data_to_send, $config['encoding']));

echo $data_to_send;