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 assign smarty variable to a php variable?

 
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
maurizio.migliore
Smarty n00b


Joined: 26 Mar 2014
Posts: 2

PostPosted: Sat Mar 29, 2014 3:54 pm    Post subject: how to assign smarty variable to a php variable? Reply with quote

In smarty 3 I have this issue:

example:

I import a php page containing the set of all possible typeOfFood, and $FOOD_VALUES is the smarty variable obtained by form2content_pro.
the in_array smarty function get in input smarty variables but $k is a php variable. How can I resolve this?

foreach ($typeOfFood as $k => $v){
{if in_array($k, $FOOD_VALUES)}
echo 'OK';
{else}
echo 'KO';
{/if}
}

tnx!!
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Mar 30, 2014 11:57 am    Post subject: Reply with quote

What do you mean by importing a PHP page?

You can't use Smarty {if} tags in a PHP file.

So can't you assign $typeOfFood to a Smarty Variable and use
{foreach} in your template?
Back to top
View user's profile Send private message
maurizio.migliore
Smarty n00b


Joined: 26 Mar 2014
Posts: 2

PostPosted: Mon Mar 31, 2014 8:46 am    Post subject: Reply with quote

Sorry,

by "import php page" I mean this...

{php}
include('list-of-typeOfFood-page.php'); #containing typeOfFoods in a php array

#then the code embedded in previous post

foreach ($typeOfFood as $k => $v){
{if in_array($k, $FOOD_VALUES)}
echo 'OK';
{else}
echo 'KO';
{/if}
}

{/php}

I import php because I'm doing the porting of a site that used it.
thank you again.
M-
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Mar 31, 2014 9:01 am    Post subject: Reply with quote

With the {php} tag you switch to PHP context and you can't use Smarty tags like {if} between {php} and {/php}.

Why don't you include the file in your main PHP script and assign $typeOfFood as Smarty variable?
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