|
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 |
manuuk Smarty n00b
Joined: 17 May 2008 Posts: 2
|
Posted: Sun May 18, 2008 8:35 am Post subject: méthode GET et message de "notice" |
|
|
Bonjour,
Je souhaite faire afficher un élément div en fonction d'une part de l'existence ou non d'une variable déclaré dans l'adresse, et si elle existe de sa valeur, pour cela dans mon fichier php j'ai :
Code: |
$news=$_GET['news'];
if( !isset($news) ) {
$news = 'no';
}
$smarty->assign('news', $news);
|
Et dans le tpl j'ai :
Code: |
<style>
{if $news eq 'yes'}
{literal}
.news {
display: block;
}
{/literal}
{else}
<!-- news off -->
{/if}
</style>
|
C'est simplement un display: none - display: block en css.
Mon problème c'est que même si cela fonctionne correctement smarty m'affiche :
Quote: |
Notice: Undefined index: news in ...index.php on line 13 | (la ligne 13 correspond à celle où $_Get se situe. Je comprend bien que si j'appelle mon site sans passer la variable dans l'adresse (ce qui est le cas quand on tape l'adresse du site sans index.php?news=), elle ne soit pas déclaré à ce moment là, mais je fais un test par la suite ...
J'ai pensé rajouter :
Code: |
$smarty->debugging = false;
$smarty->error_reporting = null;
|
juste avant dans mon fichier php, mais ça ne change rien !
Quelqu'un à une idée ? |
|
Back to top |
|
Vynka Smarty Rookie
Joined: 30 Apr 2003 Posts: 17 Location: Belgium
|
Posted: Wed May 21, 2008 8:24 am Post subject: |
|
|
Salut;
Pourquoi ne pas directement tester ton "GET", dans le PHP, au lieu de l'assigner puis de le tester. (C'est l'assignation qui lance l'erreur)
Code: |
$news = ( isset($_GET['news'] )?$_GET['news']:"no";
$smarty->assign('news', $news);
|
A tester ...
++ _________________ Au pays des Gloups!
http://www.wishlist.lu |
|
Back to top |
|
manuuk Smarty n00b
Joined: 17 May 2008 Posts: 2
|
Posted: Wed May 21, 2008 11:00 am Post subject: ok! |
|
|
Salut,
Ça marche très bien, il manquait juste une parenthèse dans ton expression
Merci beaucoup. |
|
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
|