|
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 |
spaindre Smarty Rookie
Joined: 16 Oct 2014 Posts: 7
|
Posted: Thu Oct 16, 2014 3:37 pm Post subject: HELP ; PHP TO SMARTY |
|
|
Hello
i have a test page php 1.php with this code
Code: |
<?php
$shows = $show->getShows(null,$default_language);
$shows = $misc->aasort($shows,"title");
?>
<label class="control-label">TV show</label>
<div class="controls">
<select name="show_id" id='show_id' onchange="reloadEpisode();" class="span3" >
<option value='0'>Select a show</option>
<?php
if (count($shows)){
foreach($shows as $id => $val){
$show_title = stripslashes($val['title']);
print("<option value='$id' "); if (isset($show_id) && $show_id==$id) print(" selected='selected'"); print(">$show_title</option>\n");
}
}
?>
</select>
</div>
|
i wanna try to get 1.php with this code
Code: |
<?php
$shows = $show->getShows(null,$default_language);
$shows = $misc->aasort($shows,"title");
?>
|
and 1.tpl
Code: |
<label class="control-label">TV show</label>
<div class="controls">
<select name="show_id" id='show_id' onchange="reloadEpisode();" class="span3" >
<option value='0'>Select a show</option>
{foreach from=$show_title item=show_id key=id}
<option value="{$id}"{if $show_id eq $id} selected="selected"{/if}>{$show_title}</option>
{/foreach}
</select>
</div>
|
|
|
Back to top |
|
spaindre Smarty Rookie
Joined: 16 Oct 2014 Posts: 7
|
Posted: Thu Oct 16, 2014 4:27 pm Post subject: |
|
|
BUT it's not working any help pls |
|
Back to top |
|
kowach Smarty Rookie
Joined: 26 Jan 2011 Posts: 13
|
Posted: Fri Oct 17, 2014 1:34 pm Post subject: |
|
|
You are doing it wrong. Why don't you prepare show options?
1.php
Code: |
// concat two arrays
$show_options = array( 0 => "Select a show");
foreach($shows as $id => $val)
$show_options [$id]= stripslashes($val['title']);
$smarty->assign('show_options',$show_options);
$smarty->assign('show_id',$show_id);
|
1.tpl - nice and clean
Code: |
<label class="control-label">TV show</label>
<div class="controls">
{html_options name="show_id" id="show_id" onchange="reloadEpisode();" class="span3" options=$shows_options selected=$show_id}
</div>
</label>
|
http://www.smarty.net/docsv2/en/language.function.html.options.tpl |
|
Back to top |
|
spaindre Smarty Rookie
Joined: 16 Oct 2014 Posts: 7
|
Posted: Fri Oct 17, 2014 9:19 pm Post subject: |
|
|
perfect thank you very much |
|
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
|