0

I'm using the latest stable version of Smarty and can't get this string to work. I've looked at other questions for solution to do this but none seem to work.

This is a template file (TPL), and doesn't contain any PHP at all. Note that the TPL file is compiled to a PHP script and then sent to the browser. It's not a PHP file.

Current code:

'foo{$bar}'

which outputs as:

'foo{$bar}' 

instead of the value of $bar.

What am I doing wrong?

Community
  • 1
  • 1
Alvar
  • 252
  • 1
  • 4
  • 13
  • 4
    Change it to `"foo{$bar}"`. When using single quotes the string is interpreted literally. – Gil Mar 11 '14 at 19:57
  • Is this in a PHP file or in a Smarty TPL file? – andrewtweber Mar 11 '14 at 19:59
  • Thanks @gil that solved my problem. But when should double quotes be used compared to single quotes? Want to put it as an answer and explain the difference? (: – Alvar Mar 11 '14 at 20:03
  • 1
    @Alvar : see http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – SolarBear Mar 11 '14 at 20:04
  • @SolarBear but it's not strictly a php problem since this is a TPL file. I know it's compiled into a PHP script but it's not strictly the same thing. – Alvar Mar 11 '14 at 20:06

1 Answers1

0

If you use any variables within text you have to use double-quotes " instead of single quotation marks '. Text within single quotation marks is not parsed for variables in PHP.

Dion
  • 3,145
  • 20
  • 37
  • But this is a TPL file not a PHP file. dot's doesn't work as they do in PHP why should this work then? – Alvar Mar 11 '14 at 20:15
  • I don't know this tpl-files, just answered in regard to PHP as your question was tagged with php and you didn't say that you aren't using PHP... Sorry – Dion Mar 11 '14 at 20:17
  • Is the problem solved now? If this was indeed the issue, I'm not sure what the remaining problem is. Unless the _real_ question is why would `'` and `"` be treated differently in a TPL file? – Mr Lister Mar 11 '14 at 21:38