|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
atmoner Smarty n00b
Joined: 06 Feb 2011 Posts: 2 Location: France
|
Posted: Sat Sep 24, 2011 4:43 pm Post subject: Class et foreach |
|
|
Bonjours,
Alors voila, j'ai un petit souci pour adapter mon site (écrit simplement dans des fichier .php mélanger avec le html)
J'utilise des fonction par une class et je me retrouve un peu bloquer pour faire transcrire ma fonction dans un foreach.
Je m'explique, voici ma classe que je devrais avoirs dans mon php:
Code: | <?php
foreach ($articles as $k => $v) {
echo $v['title']
echo $MaClass->printArticle($v['text']);
} ?> |
Pour le title, pas de souci... mais comment ajouter une class au tpl !
J'ai bien essayer de faire un foreach dans le php et faire apparaître le résultat dans le foreach du tpl, mais forcement ça ne fonctionne pas (il affiche le même text pour tous les article)
Si quelqu'un a une petite idée sur la question, je suis preneur
Amicalement atmoner |
|
Back to top |
|
Code62 Smarty Rookie
Joined: 21 Jun 2011 Posts: 12 Location: Work@Liège.be
|
Posted: Wed Sep 28, 2011 11:11 am Post subject: |
|
|
Salut,
Si j'ai bien compris, ceci devrait faire l'affaire:
php
Code: | $smarty->assign(array(
'ARTICLES' => $articles,
'MACLASS' => $MaClass
)); |
tpl
Code: | {foreach from=$ARTICLES item=ARTICLE}
<h1>{$ARTICLE.title}</h1>
<p>{$MACLASS->printArticle($ARTICLE.text)}</p>
{/foreach} |
|
|
Back to top |
|
atmoner Smarty n00b
Joined: 06 Feb 2011 Posts: 2 Location: France
|
Posted: Wed Oct 12, 2011 11:09 pm Post subject: |
|
|
bonjours ! et déjà, merci de ta réponse...
Ton code est bon, à peu de chose prêt, je te remercie |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|