View previous topic :: View next topic |
Author |
Message |
dmm2020 Smarty Rookie
Joined: 29 Nov 2009 Posts: 27
|
Posted: Mon Mar 12, 2012 2:38 am Post subject: Replacement for echoing function output (raw code) in Smarty |
|
|
I am looking to eventually do away with Autoloader::loadClass('SmartyBC');
But one problem is some of my script requires use of javascript and mixed html stored in MySQL. When I try to assign that to a variable, it either shows white space, error, or if I try literal tags, it shows the raw script and not what it's supposed to.
Is there a fix to replace the equivalent "{php}echo myads(1);{/php}?
This is one thing that is stopping me from fully implementing Smarty recommended methods into my template. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Mar 12, 2012 2:56 am Post subject: Re: Replacement for echoing function output (raw code) in Sm |
|
|
dmm2020 wrote: | I am looking to eventually do away with Autoloader::loadClass('SmartyBC');
But one problem is some of my script requires use of javascript and mixed html stored in MySQL. When I try to assign that to a variable, it either shows white space, error, or if I try literal tags, it shows the raw script and not what it's supposed to.
Is there a fix to replace the equivalent "{php}echo myads(1);{/php}?
This is one thing that is stopping me from fully implementing Smarty recommended methods into my template. |
There should be no problem for Smarty to display any text from a variable. How the browser interprets that text may be your issue? |
|
Back to top |
|
dmm2020 Smarty Rookie
Joined: 29 Nov 2009 Posts: 27
|
Posted: Mon Mar 12, 2012 3:14 am Post subject: |
|
|
I don't think it's a browser issue. If I echo it inside PHP tags using SmartyBC it works fine. However, if I try to load the html from a field in MySQL and assign it to a Smarty variable, it does not work. An example to look at, is I store Google Adsense code in the database. I extract that using $ADS->showads(1) and assign it using $smarty->assign('topad',$ADS->showads(1)); but this method results in nothing but white space. This lead to frustration before and I went back to SmartyBC, but I am hoping that somewhere, someone has a solution for this.
The problem is that the html has javascript in it and literal tags do not work in this case. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Mar 12, 2012 3:17 am Post subject: |
|
|
If you do this:
Code: | $smarty->assign('topad',$showads(1));
$smarty->display('my.tpl'); |
And the smarty template is nothing but this:
Does it print the text on the browser ok? If so, the next step:
And view the browser source. Does it look right?
The content of the variable should not matter, Smarty should just echo it. If the content is something (ie javascript) the browser might act upon, that might be where the problem is. |
|
Back to top |
|
dmm2020 Smarty Rookie
Joined: 29 Nov 2009 Posts: 27
|
Posted: Mon Mar 12, 2012 3:39 am Post subject: |
|
|
The code coming out of the database looks like this:
Code: | <center><script type="text/javascript"><!-- google_ad_client = "ca-pub-6392921418651416"; /* 468x60, created 12/9/09 */ google_ad_slot = "3609869863"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script></center> |
Now when I use what you suggested, the raw text is displayed which is the problem. It's supposed to load Adsense. I can't use literal tags here as they do not work. The {$topad|escape} does nothing different than without.
This is where in the past it forced me back to using PHP tags and loading SmartyBC. I would like to get around it, but the only way is if this solution can be resolved somehow. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Mar 12, 2012 3:42 am Post subject: |
|
|
If {$topad|escape} and {$topad} do the exact same thing, then you must have $smarty->escape_html enabled (this is disabled by default), or you must have a default modifier or filter or plugin involved in some way to escape it. Maybe the content is escaped coming out of the DB, and thus the data assigned to Smarty is already escaped? Smarty will not escape this content by default. |
|
Back to top |
|
dmm2020 Smarty Rookie
Joined: 29 Nov 2009 Posts: 27
|
Posted: Mon Mar 12, 2012 3:57 am Post subject: |
|
|
I found that it was the way the script was being saved to the database. I reverted back to the recommended Smarty conventions and this time it works. I need to look at how it's being escaped and unescaped in the ads class.
Least now I can do away with SmartyBC. |
|
Back to top |
|
dmm2020 Smarty Rookie
Joined: 29 Nov 2009 Posts: 27
|
Posted: Mon Mar 12, 2012 4:16 am Post subject: |
|
|
Before I forget, thanks for your time. You were correct. I found error after I learned to look "outside" the box where I was focused on. |
|
Back to top |
|
|