• Home
  • Free Stuff
  • About
  • Contact

How to Add PHP & Javascript Code to Smarty Template (Serendipity, Pligg)

January 12, 2010

I manages various website and some of them are running on Serendipity blog engine or a Digg-looks-alike, Pligg. Both engine use Smarty framework based on PHP code. Although Smarty built from PHP engine, it has different style in code writing than another CMS based on PHP like WordPress. Smarty using their own tags that will be parsed on their engine, so adding Javascript or PHP code can not be directly written in the related tpl file (an extension for Smarty template).

If you wish to add a Javascript code like Google Adsense or a PHP code into Smarty template, use the following tips :

  1. Open your related tpl file and use {php} and {/php} tags to include the PHP file
    [code language=’php’]
    {php}include(‘/home//vavai/vavai.net/myphpfile.php’);{/php}
    [/code]
    Please note that I would prefer to use absolute path and not the relative path instead.
  2. Open your related tpl file and use the {literal} and {/literal} tags to add the Javascript code. Place your Javascript code inside literal tags as shown on the following example :
    [code language=’php’]
    {literal}{/literal}
    [/code]

On the sample #1, I would prefer to include the php file rather than write the PHP code directly on Smarty file. It will make a code a lot easier to manage, clean, easy to understand and we have a flexible way to add or remove the related file.

Google AdsensePHPSmartySUSE Familytips
Share

Linux

Masim "Vavai" Sugianto
Traveller, Open Source Enthusiast & Book Lover. Works as Independent Worker & Self-Employer.

Comment


1/12/2010 Update « Go Code
January 12, 2010 at 12:28
Reply

[…] How to Add PHP & Javascript Code to Smarty Template (Serendipity … […]



Grady Bekele
March 5, 2010 at 08:45
Reply

Hi, I came across this blog post while searching for help with JavaScript. I have recently changed browsers from Google Chrome to IE. Now I seem to have a problem with loading JavaScript. Every time I go on a page that requires Javascript, my computer does not load and I get a “runtime error javascript.JSException: Unknown name”. I can’t seem to find out how to fix it. Any help is very appreciated! Thanks



Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Recent Posts

    • Januari 2021 Portfolio Update
    • December 2020 Portfolio Update
    • After a While
    • Life goes On : Farming
    • Pursuing FIRE in Indonesia : Are You Prepared For A Recession?
    • VirtualBox Error Kernel Driver not Installed (rc=-1908) on Zorin OS 15.2
    • ZorinOS on Intel NUC Hades Canyon Series NUC817HVK
    • Banana Farm
    • Zorin OS 15.2 Ultimate
    • Haraka and LDAP Authentication with Zimbra



© Copyright LetsBlog Theme Demo - Theme by ThemeGoods