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

how to call the code below in TPL?

 
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 -> General
View previous topic :: View next topic  
Author Message
terra
Smarty Rookie


Joined: 27 Jul 2011
Posts: 26

PostPosted: Wed Mar 20, 2013 2:24 am    Post subject: how to call the code below in TPL? Reply with quote

hi,

how to call the code below in TPL?

Quote:
if( isset( $_SESSION["minhalista"][$id]) == $id ){
echo '
<div class="festa">
id: '.$id.'<a href="#" class="add selecionado" rel="'.$id.'" nm="'.$nome.'">Selecionado</a>
</div>
';
}else{
echo '
<div class="festa">
id: '.$id.'<a href="salva.php?id='.$id.'&acao=add" class="add selecionar" rel="'.$id.'" nm="'.$nome.'" nm2="'.$preco.'">Selecionar</a>
</div>
';
}
}



Thanks[/quote]
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Mar 20, 2013 2:45 pm    Post subject: Reply with quote

This doesn't make much sense:

Code:
if( isset( $_SESSION["minhalista"][$id]) == $id )


isset() returns true or false, testing if that equals an $id is probably not what you want. maybe:

Code:
if(isset($_SESSION["minhalista"][$id]) && $_SESSION["minhalista"][$id] == $id)


That said, you can do this in a template:

Code:
{if isset( $smarty.session.minhalista.$id ) &&  $smarty.session.minhalista.$id == $id }
  <div class="festa">
    id: {$id}<a href="#" class="add selecionado" rel="{$id}" nm="{$nome}">Selecionado</a>
  </div>
{else}
  <div class="festa">
    id: {$id}<a href="salva.php?id={$id}&acao=add" class="add selecionar" rel="{$id}" nm="{$nome}" nm2="{$preco}">Selecionar</a>
  </div>
{/if}


make sure $id, $nome and $preco are assigned as smarty variables.
Back to top
View user's profile Send private message Visit poster's website
terra
Smarty Rookie


Joined: 27 Jul 2011
Posts: 26

PostPosted: Wed Mar 20, 2013 6:16 pm    Post subject: Reply with quote

Hi,

thanks.

He takes the record id session in the php, but not caught by smarty, what could be wrong?

Quote:

in tpl
{foreach from=$var_list item=i}

in php

$var_list[$i]['id']=$row['business_id'];



I appreciate any help


Thanks again
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Mar 20, 2013 7:01 pm    Post subject: Reply with quote

not sure what that means. you might want to explicitly assign the record id to a smarty variable instead of trying to access the session from smarty.
Back to top
View user's profile Send private message Visit poster's website
terra
Smarty Rookie


Joined: 27 Jul 2011
Posts: 26

PostPosted: Wed Mar 20, 2013 7:18 pm    Post subject: Reply with quote

Hi,

see

Quote:
{if isset( $smarty.session.minhalista.$id ) && $smarty.session.minhalista.$id == $i.id }
<div class="festa">
id: {$i.id}<a href="#" class="add selecionado" rel="{$i.id}" >Selecionado</a>
</div>
{else}
<div class="festa">
id: {$i.id}<a href="salva.php?id={$i.id}&acao=add" class="add selecionar" rel="{$i.id}" >Selecionar</a>
</div>
{/if}


i can help me?

Thanks
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 -> General 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