|
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 |
maurizio.migliore Smarty n00b
Joined: 26 Mar 2014 Posts: 2
|
Posted: Sat Mar 29, 2014 3:54 pm Post subject: how to assign smarty variable to a php variable? |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Mar 30, 2014 11:57 am Post subject: |
|
|
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 |
|
maurizio.migliore Smarty n00b
Joined: 26 Mar 2014 Posts: 2
|
Posted: Mon Mar 31, 2014 8:46 am Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Mar 31, 2014 9:01 am Post subject: |
|
|
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 |
|
|
|
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
|