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)

Adsense Code with Smarty

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:

Adsense ads with code

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

6 Comments on “Adsense Code in Smarty”

  1. Wayne Smallman Says:

    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…

  2. Flukeit Says:

    I agree Wayne. I more than likely will be purchasing a reference book to help me learn it.

  3. anthony greene Says:

    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.

  4. chote Says:

    Thank you so much, this helped me!

    Just added {literal}..adsense..{/literal} and it works in my PHPLD dir.

  5. muhammad waqas-19886 Says:

    thank you for useful information.it will help me to earn extra money from adsense

  6. Ben@ yeast infection in men Says:

    @Mandy- If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. Speak about security holes :)



purchase Zolpidem | replacement lcd laptop screens