Question

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?

Was it helpful?

Solution

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}";

OTHER TIPS

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.

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.

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

literal

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top