Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new at Smarty. I have a smarty array $order_info

How can I assign the value {$order_info.email} to a PHP string?

I hope someone can help me!

Solution:

{/php}
     {$order_info.email}
{php}
share|improve this question
1  
What exactly are you trying to do? Generally smarty is for displaying stuff not for adding values to things to pass back to PHP. –  RightHandedMonkey Aug 6 '13 at 15:05
    
Yes i know. I want to convert the smarty to php string for a hack. –  Bas Aug 6 '13 at 15:07
    
@RightHandedMonkey I think he wants to assign email value to some other variable in loop. –  Eugene Aug 6 '13 at 15:07
    
@Bas how on earth is that supposed to work? Could you give some more details please? –  Bart Friederichs Aug 6 '13 at 15:08
    
what has been answered (and accepted) below makes no sense for your own edit of the question. Also the question itself is not clear what you're asking. I don't see a reason to keep this on a Q&A site and therefore voted to close it. Will also vote to delete it. Just wanted to let you know. –  hakre Aug 11 '13 at 5:24
add comment

1 Answer

up vote 0 down vote accepted

According to http://www.smarty.net/docs/en/language.function.assign.tpl you should be able to run the following code:

Smarty template

{assign var="email" value=$order_info.email}

PHP Script

// First fetch the template!
$whole_page = $smarty->fetch('index.tpl');

// Then get the variable:
$email = $smarty->getTemplateVars('email');
echo "The email in a PHP variable: " . $email;
share|improve this answer
    
This doesnt work. If i do {$order_info.email} this then the emailadres diplayed. Do i need to give a key?! –  Bas Aug 6 '13 at 15:18
    
Sorry, updated the code after rereading the documentation. –  roggan87 Aug 6 '13 at 15:39
    
i am getting this notice Notice: Undefined variable: smarty in. Its a opensource software. how can i find the wright variable –  Bas Aug 8 '13 at 9:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.