Your Problem...

From: Date: Tue, 30 Jul 2002 14:45:30 +0000
Subject: Your Problem...
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5512@lists.php.net to get a copy of this message
Why not use an "if" outside the section? Try to set an flag in the php script, if the array that should pass the section is empty. In the template you can use an "if"-construct to check if the flag is set or not. (So you will not need an sectionelse) Example: <?php $sql = "SELECT user_id FROM users"; $res = mysql_query($sql) . die("There was an error in your sql: ". $sql); if(!$row = mysql_fetch_array) { $smarty->assign("section_empty", "true"); } . . . ?> Filling the array is your job...;-) Template: {if $section_empty != 'true'} <UL> {section name=userlist loop=$users} <LI>{$users[userlist].user_name}</LI> {/section} </UL> {else} There are no names... {/if} Mhhh... Okay it is an "if"-construct, but it will work... "Håvard lindset" <elindset@hoved.net> schrieb im Newsbeitrag news:<001101c23784$4d26e2c0$74b8a1d5@lindset>... > Hi, > > I wondered if there were a way to prepend and append something to a section? > Let me give you all an example of what I think would be a good idea: (this > is kind of a feature suggestion, unless there are other ways to achieve what > I'm trying to do) > > --- > > {section name=somesection loop=$variable prepend="<ul>" > append="</ul>"} > <li>{$variable[somesection].name}</li> > {sectionelse} > There were no names! > {/section} > > --- > > What I want to do is to only prepend and append something to the actual > section (not the sectionelse). And yes, I know the prepend and append > properties is non existent, I just wanted to show you how I would like it to > be. > > I could just put <ul> and </ul> before and after the section, but because I > don't want the "There were no names!" message inside those tags. > > I can't put them inside the section either, because then there would be > created new <ul>'s every time it iterates through the array. > > I don't want to have {if}'s for checking wether or not to display the > <ul>'s > either. > > > How can I achieve what I want to do? > Thank you for your help! > > Best regards, > Håvard Lindset > kBase Developer > http://www.webpixels.net > http://kbase.webpixels.net >

« previous php.smarty.general (#5512) next »