Adsense Code in Smarty
I own several websites that are link directories. Most of them are run on the phpLD Link Directory script. One of the more challenging parts of maintaining and getting these directories going is dealing with Smarty. Before I knew any better, I would get frustrated when trying to add code, then not seeing the end result on the page displayed.
Smarty does weird things, as I’m still learning and understanding.
A prime example of this is adding Adsense code to template files. I was attempting to add Adsense code to one of my templates, and I simply added my Adsense code.
The result was not what I planned. The ads displayed, but were not correct as shown here.(Image at 75% scale)

The ad just didn’t look right, and it seems as though the “ads by Google” text was missing.
After doing some investigating, I learned that I had to add “literal” tags around the code as such:
{literal}
Adsense code
{/literal}
This was much better, as it produced the desired ad:

I still run across confusion when I attempt to do other things similar, and still cannot figure them out. These are growing pains, I’m sure as I will eventually grow out of them.
Explore posts in the same categories: Coding, Lessons Learned
January 6th, 2007 at 10:27 am
By far the biggest problem with Smarty is the help files.
I can well imagine how long some people spend in there looking for a function.
I’m one of them. I’ve been there…
January 6th, 2007 at 4:21 pm
I agree Wayne. I more than likely will be purchasing a reference book to help me learn it.
January 7th, 2007 at 11:49 am
I am constantly banging my head on the smarty thing. I guess its time to “search” for another resource for getting info also. Thanks for the heads up on the literal tag, waiting for adsense to be approved.
January 29th, 2010 at 6:21 am
Thank you so much, this helped me!
Just added {literal}..adsense..{/literal} and it works in my PHPLD dir.
February 18th, 2011 at 10:40 am
thank you for useful information.it will help me to earn extra money from adsense
August 24th, 2011 at 7:03 am
@Mandy- If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. Speak about security holes