Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Class et foreach

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: French
View previous topic :: View next topic  
Author Message
atmoner
Smarty n00b


Joined: 06 Feb 2011
Posts: 2
Location: France

PostPosted: Sat Sep 24, 2011 4:43 pm    Post subject: Class et foreach Reply with quote

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
View user's profile Send private message
Code62
Smarty Rookie


Joined: 21 Jun 2011
Posts: 12
Location: Work@Liège.be

PostPosted: Wed Sep 28, 2011 11:11 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
atmoner
Smarty n00b


Joined: 06 Feb 2011
Posts: 2
Location: France

PostPosted: Wed Oct 12, 2011 11:09 pm    Post subject: Reply with quote

bonjours ! et déjà, merci de ta réponse...
Ton code est bon, à peu de chose prêt, je te remercie Wink
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: French All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP