user840298
user840298

Reputation:

How can I assign a smarty variable to a PHP variable

How can I assign a smarty variable to a PHP variable. I have

{assign var=arrayname value="/"|explode:$form.attributes}
{assign var=id value=$arrayname.2}

I want to assign the smarty variable id to a php variable

<?php  
    // I want $id here 
?>

How can I do this?

Thanks in advance

Upvotes: 1

Views: 4060

Answers (3)

Jla
Jla

Reputation: 11384

It is possible to use php in a smarty template but:

"This is for advanced users only, not normally needed and not recommended."

The whole point of the smarty template is to keep your business logic in a separate view. Therefore you should deal with your variables in the php page then assign them to the template as in Lucifer Orichalcum's example.

If the user Id value you a trying to retrieve comes from a form you have to deal with the form values in the .php file ($_POST['id']) not in the .tpl Same rule for your sessions variables.

Can you tell us more about where the Id comes from in the first place ?

Upvotes: 0

Toby Allen
Toby Allen

Reputation: 11221

This isn't really a situation you should find yourself in.

You should be able to either do what you want to do entirely in smarty or entirely in php.

If you explain in detail what your trying to do we can help you with one or the other

Upvotes: 0

Lucifer Orichalcum
Lucifer Orichalcum

Reputation: 231

I don't quite understand...how was your $arrayname passed to Smarty....? I assume you have used something like

<?php
$smarty->assign('arrayname',$arrayvariable)
?>

So in PHP there is equation:

$you_have_wanted==$arrayvariable[2]

Upvotes: 1

Related Questions