[Smarty] Inclure du php dans un tpl
Bonjour, n'ayant pas de réel connaissance en tpl je fais appelle à vous.
En faites un un script php qui me génére des liens vers des formulaire et je veux l'intégrer à mon templates.
Le script est comme ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
<?php
$dirname = '../../webform';
$dir = opendir($dirname);
// dossier "client" : pas dans dossier
$dir_not_array = array('.', '..', 'css', 'js', 'temp_webform');
// fichier image : extensions autorisées
$extensions_ok_array = array('jpg', 'jpeg', 'gif', 'png');
// on parcourt le dossier "webform"
while($file = readdir($dir)) {
// si il existe un dossier "img" dans le $file, et que $file n'est pas pas l'array
// alors $file est un dossier "client" !
if(is_dir($dirname.'/'.$file.'/img') && !in_array($dirname.'/'.$file, $dir_not_array)) {
// on parcourt les fichiers du dossier $file
foreach (glob($dirname.'/'.$file.'/img/logo.*') as $filename) {
// on cherche les fichier "logo.*", dont l'extension est dans la liste
if (file_exists($filename) && in_array(strtolower(pathinfo($filename, PATHINFO_EXTENSION)), $extensions_ok_array)) {
echo '<a href="'.$dirname.'/'.$file.'/index.php" style="text-decoration:none"><img class="lien" src="'.$filename.'" /></a>'.' ';
}
}
}
}
closedir($dir);
?> |
Ce script vise à remplacer le code que j'ai mis dans mon templates (index.tpl) qui est comme ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| <table width="100%" cellspacing="0" cellpadding="0" border="0" class="small">
<tbody>
<tr>
<td nowrap="" style="padding-left:10px;padding-right:50px" class="moduleName"><a class="hdrLink" href="">Fiches de typologie</a></td>
</tr></tbody></table>
<h3 align="center"> Fiches typologie des appels disponibles pour les clients suivant : </h3>
<br/>
<hr/>
<div id="Lien" >
<div id="Logo" align="center">
<a href="{$SCRIPT_NAME}/../webform/sfr/index.php" target="_blank" style="text-decoration:none" > <img class='liencarre' src="../webform/sfr/img/logo.png" width="80px" height="80px"> </a>
<a href="{$SCRIPT_NAME}/../webform/irt/index.php" style="text-decoration:none"> <img class='lienrectangle' src="../webform/irt/img/logo.jpg" width="150px" height="70px"> </a>
 
<a href="{$SCRIPT_NAME}/../webform/kdopays/index.php" style="text-decoration:none"> <img class='lien' src="../webform/kdopays/img/logo.jpg" width="150px" height="60px"> </a>
<a href="{$SCRIPT_NAME}/../webform/apavou/index.php" style="text-decoration:none"> <img class='lien' src="../webform/apavou/img/logo.jpeg" width="150px" height="60px"> </a>
<a href="{$SCRIPT_NAME}/../webform/apria/index.php" style="text-decoration:none"> <img class='lien' src="../webform/apria/img/logo.png" width="100px" height="50px"> </a>
<a href="{$SCRIPT_NAME}/../webform/tereos/index.php" style="text-decoration:none"> <img class='lien' src="../webform/tereos/img/logo.jpg" width="80px" height="80px"> </a>
</div>
<hr/>
</div> |
Ainsi au lieu de rentrer tous les a href a la main le script le fait automatiquement.
a prtir de mon fichier index.php, j'appel mon tpl de cette maniere :
Code:
$smarty->display(vtlib_getModuleTemplate('Fiches_Typo', 'index.tpl'));