0

How I can place a javascript variable within smarty?

Following doesn't work:

{url controller=myController action=detail id='+obj.id+' forceSecure}

1
  • 1
    doesn't work isn't a proper problem statement. Explain what you expect this code to do and what it is or isn't doing as expected. Also take note of errors thrown in console Commented Jan 17, 2015 at 13:31

3 Answers 3

1

as smarty is serverside compiled you wont be able to do it like you expect, but you could do sth like

<script>

var url = "{url controller=myController action=detail forceSecure}"+"&id="+obj.id

</script>

i have no experience with smarty but if ´id´ is part of the url, keeping it blank will possibly throw an exception, so you can parse the parameter as url parameter like in my example or you send and parse it as POST parameter

Sign up to request clarification or add additional context in comments.

Comments

0

Javascript is client side scripting language. You can not use javascript in the server side template engine smarty. This is because the template is going to get evaluated at the server.

Comments

0

You can't assign a client-side value to a smarty variable, as smarty is a templating language that runs on the server. Smarty assignments can only be done on the server-side, that is to say, from PHP.

assign smarty

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.