3

I find this very strange, must be something I'm doing wrong, but still... I'm working on a page using PHP and TPL files. In my TPL file, there's a place in the footer for some extra lines if needed.

For instance, formchecking with Javascript.

so in PHP I did this:

$foot = "<script type=\"text/javascript\">if(document.getElementById){loadEvents();}</script>";

the $foot variable is then parsed and the result in HTML is this:

<script type="text/javascript">if(document.getElementById)</script>

So {loadEvents();} went missing.

Does anybody see what I'm missing here... I'm seriously not finding it. Did I forget to escape a character or something?

2
  • by TPL files do you mean Smarty? How is the $foot getting into the tpl file? Commented Dec 1, 2008 at 15:05
  • Maybe telling people that you use a template engine instead of letting them guess would have been a nice thing to do. Commented Dec 1, 2008 at 15:13

4 Answers 4

8

Obviously the template engine you are using eats away the part in curly braces.

Try something like:

$foot = "{literal}<script type=\"text/javascript\">if(document.getElementById){loadEvents();}</script>{/literal}";
Sign up to request clarification or add additional context in comments.

8 Comments

not working, I also noticed that the last quotation mark in your solution is a double, fixed that, still not working
Yes. Seen that too late, fixed.
-1 because this is simply not true echo "{1+1}"; will not output "2". The {} within double quotes is only used for disambiguating variables, e.g. "he drank some {$beer}s." The issue here is most likely the templating engine, in which case a fix would depend on which engine was in use.
This isn't correct - the $foot = "<script... etc. line evaluates correctly
That there was a template engine involved was not clear to me. Should have thought of that though.
|
2

It looks like you're using a template engine like Smarty, which tries to parse anything it finds within braces.

This page from the smarty documentation explains how to make smarty ignore sections it would otherwise parse.

Comments

1

I believe with {} that PHP is expecting a variable within them. I haven't tested this, but try using single quote instead of double-quotes.

2 Comments

-1 because php doesn't parse {var} as a variable. It uses $var, ${var}, or {$var}
I didn't say {var} ... ? All I said is that it expects a variable; in which case yes it would be along the lines of {$var}
1

If you are using smarty you could use the {literal}.

literal

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.