Jump to content

How to write a custom PHP/ HTML code on pages using any free module ?

Recommended Posts



          Its my 2nd day on prestashop and i'm stuck on 1 issue and i'm not able to get any perfect solution on it.


          My requirement is to add a some static HTML code which should be page specific and position specific. For example i want to add some HTML block top of the main contents (Not in to the Header), and some HTML block just before the footer.


          I tried one module 'Custom CMS information block', but it does not provide any option where you want to integrate the block also doesnt specify the position. And all code in the block display at 1 position on only home page.


          Is there any way to write the code in Admin and i can call these blocks any where on the page using their IDs etc.


Please Help !!

Share this post

Link to post
Share on other sites

you can use modules like content box of html box

note, that modules can't run php scripts, only static things like js,css,html


to use php you have to alter prestashop core php files (or module files)

at the moment there is no other way, unfortunately

Share this post

Link to post
Share on other sites

Thanks for reply. I already tried 'html box' module, but it accepts only one block content (Either for Header / Top / Footer etc. ). I cant add more than 1 block content at a time for same page through it. Its ok if modules supports only static contents but it should be page and position specific. Any help will be appreciated. Thanks.

Share this post

Link to post
Share on other sites

I did it by using same 'Custom CMS information block' module and doing some coding.

First - Added HTML blocks in 'Custom CMS information block' module. Took their primary IDs from DB.


Second - In IndexController added following code -


$this->context->smarty->assign(array('HOOK_HOME' => Hook::exec('displayHome'),
            'HOOK_HOME_BLOCK1' => Hook::exec_block(1),
            'HOOK_HOME_BLOCK2' => Hook::exec_block(2),
            'HOOK_HOME_TAB' => Hook::exec('displayHomeTab'),
            'HOOK_HOME_TAB_CONTENT' => Hook::exec('displayHomeTabContent')


where Hook::exec_block(1) ---> 1 is the primary key from 'info' and 'info_lang' table. same for Hook::exec_block(2). 'exec_block' is a custom function.


In Hook.php class file wrote a custom function -

public static function exec_block($block_id)
        $id_lang = (int)Context::getContext()->language->id;
        $id_shop = (int)Context::getContext()->shop->id;
        $sql = 'SELECT r.`id_info`, r.`id_shop`, rl.`text`
            FROM `'._DB_PREFIX_.'info` r
            LEFT JOIN `'._DB_PREFIX_.'info_lang` rl ON (r.`id_info` = rl.`id_info`)
            WHERE rl.`id_lang` = '.(int)$id_lang.' AND  r.`id_shop` = '.(int)$id_shop .' AND r.`id_info` = '.(int)$block_id;
        $row = Db::getInstance()->getRow($sql);
        return $row['text'];


And at last in index.tpl added a block where i want to place as -

{if isset($HOOK_HOME_BLOCK1) && $HOOK_HOME_BLOCK1|trim}
    <div class="clearfix">{$HOOK_HOME_BLOCK1}</div>
    {if isset($HOOK_HOME_TAB) && $HOOK_HOME_TAB|trim}
        <ul id="home-page-tabs" class="nav nav-tabs clearfix">
    <div class="tab-content">{$HOOK_HOME_TAB_CONTENT}</div>
{if isset($HOOK_HOME) && $HOOK_HOME|trim}
    <div class="clearfix">{$HOOK_HOME}</div>

{if isset($HOOK_HOME_BLOCK2) && $HOOK_HOME_BLOCK2|trim}
    <div class="clearfix">{$HOOK_HOME_BLOCK2}</div>


Done :)

Edited by sphinx.ganesh (see edit history)

Share this post

Link to post
Share on other sites
This topic is now closed to further replies.
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More