Jump to content

Hook modules into CMS page?


codemj

Recommended Posts

Title asks a simple question is it possible via the backend? If not how it is possible? I would like to create static content for different part of the store and hook modules to that content like top10 list and featured product etc.. I have flowed trough google and forum search but haven't find nothing yet...

Any good tips how to do this? I believe I could create a hook and transplant modules to that hook and modify the cms template to enable module hooking for cms pages? But if someone has done this before somehow.. I would like to hear about it! :)

Link to comment
Share on other sites

I will give you a brief info how I did this or how I'm planning to end this :)
It's still work in progress but here is what I have done.


1. Added a modification to cms.tpl (yes I'm using cms friendly url in statement cause I believe it has to be unique? ;)
->

{ if $cms->link_rewrite == 'MYCMSPAGE' }
{$HOOK_MYCMSPAGEHOOK}
{/if}



2.1 [forgot one of the most important one!!]
- ok before you can use the actual hook inside the desired page (any page) remember following
- in this example we are adding hook to cms page so we need to assign hook to smarty also @ cms.php

So find @cms.php

   $smarty->assign(array(
       'cms' => $cms,
       'content_only' => intval(Tools::getValue('content_only'))
   ));
   $smarty->display(_PS_THEME_DIR_.'cms.tpl');



and add your hook to smarty assign like this

   $smarty->assign(array(
       'cms' => $cms,
       'HOOK_MYCMSPAGE' => Module::hookExec('mycmspage'), // Custom hook for mycmspage
       'content_only' => intval(Tools::getValue('content_only'))
   ));
   $smarty->display(_PS_THEME_DIR_.'cms.tpl');



- above will enable the usage of $HOOK_MYCMSPAGE in cms.tpl

2. SQL Added a row to ps_hook table - Identical to previous hooks but with my hook id, name and description
-> after this I'm able to see new target in module transplant page.
-> Ok now I can hook a module which I want to mycmspagehook but still It won't show it.
3.
-> third step is to modify module_name.php file in the desired module folder and add call and hookfunction for mycmspagehook.

- first add this row to modulename.php file (which represent module you want to hook to cms page).

!$this->registerHook('myCmsPagehook') OR 


- Add it below this

!$this->registerHook('rightColumn') OR

or something similar.
- next step is to copy for example "function hookRightColumn" and rename it to hookMycmspagehook. Example below.

    function hookLeftColumn($params)
   {
       return $this->hookRightColumn($params);
   }

   /* CMS hook test */
   function hookMycmspagehook($params)
   {
       return $this->hookRightColumn($params);
   }




So now if I go to cms page "mycmspage" I can see that the module I did transplant is showing on the cms page. Now with some little html and css I can create a totally custom content page with special modules hooked inside.


With a large amount of cms pages and need of modules inside them would be easier to create a simple module which would add a simple management that would allow cms page to be automatically be added to the hook table and do the necessery modifications to cms.tpl?

ps. don't do this if you don't understand it.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Hi!
Please, can someone explain this step with more details because there is no other discussion about it in this forum? I cant find a ps_hook table in a database or in files... there is no SQL I use now... Please, its very important to me to know how to make it possible to transplant module into a CMS page.

Thanks in advance!

Link to comment
Share on other sites

Hi!
Please, can someone explain this step with more details because there is no other discussion about it in this forum? I cant find a ps_hook table in a database or in files... there is no SQL I use now... Please, its very important to me to know how to make it possible to transplant module into a CMS page.

Thanks in advance!


Hi artmaker, are you saying that you don't have any management to your sql database? Its very important that you add custom hook to sql if you want to call custom hooks, from tpl file.. (or atleast I have understand it that way).

when you call in smarty template {$HOOK_mycmspage} the part "myhook" is queried from the sql? When you have done this hook it will appear in the "transplant module list". And remember $hook_mycmspage is unique so it will point only to the one cms page you have created. So you have to create sql rows to every cms page where you want transplant modules.

I'm planning to create somekind of module or a tool that will add a checkbox to cms page creation that will ask "do you want to enable transplant modules on this cms page". Maybe someday in 2011..


It might be possible to call custom hooks already in the cms.php file like tomerq3 previously said but I haven't investigated how it should be done trough it.
Link to comment
Share on other sites

Hi!
Please, can someone explain this step with more details because there is no other discussion about it in this forum? I cant find a ps_hook table in a database or in files... there is no SQL I use now... Please, its very important to me to know how to make it possible to transplant module into a CMS page.

Thanks in advance!


Hi artmaker, are you saying that you don't have any management to your sql database? Its very important that you add custom hook to sql if you want to call custom hooks, from tpl file.. (or atleast I have understand it that way).

when you call in smarty template {$HOOK_mycmspage} the part "myhook" is queried from the sql? When you have done this hook it will appear in the "transplant module list". And remember $hook_mycmspage is unique so it will point only to the one cms page you have created. So you have to create sql rows to every cms page where you want transplant modules.

I'm planning to create somekind of module or a tool that will add a checkbox to cms page creation that will ask "do you want to enable transplant modules on this cms page". Maybe someday in 2011..


It might be possible to call custom hooks already in the cms.php file like tomerq3 previously said but I haven't investigated how it should be done trough it.


Now I know that I have management to my databases with PhpMyAdmin but I can't find the table "PS_HOOK" in my prestashop database, or am I supposed to create it?
Link to comment
Share on other sites


No, I have management to my databases with PhpMyAdmin but I can't find the table "PS_HOOK" in my prestashop database, or am I supposed to create it?


Ok I try to be more spesific =) there is a table called hook in your database, so replace ps with "YOUR_DB_PREFIX"_hook and look again? I really think hook table is one of the default tables in prestashop db structure?
Link to comment
Share on other sites


No, I have management to my databases with PhpMyAdmin but I can't find the table "PS_HOOK" in my prestashop database, or am I supposed to create it?


Ok I try to be more spesific =) there is a table called hook in your database, so replace ps with "YOUR_DB_PREFIX"_hook and look again? I really think hook table is one of the default tables in prestashop db structure?


Thanks! Now I found it.

{if !$content_only}
   {capture name=path}{l s=$cms->meta_title}{/capture}
   {include file=$tpl_dir./breadcrumb.tpl}
{/if}
{include file=$tpl_dir./binding_top.tpl}
{if $cms}

       {$cms->content}

{else}
   {l s='This page does not exist.'}
{/if}


{if !$content_only}

{l s='Home'}
{/if}
{include file=$tpl_dir./binding_bottom.tpl}
{ if $cms->link_rewrite == 'MYCMSPAGE' }
{$HOOK_MYCMSPAGEHOOK}
{/if}



That's how my CMS.TPL looks like in the "theme" folder.

And I added a row to my "hook" table called CMS with 1 length (with PhpMyAdmin of course) and I checked if it would be visible on the transplant page as you mentioned that it would be but it wasn't there. Or what is it supposed to be called? I searched only for the words "CMS and "MYCMSPAGE" in the listbox.

Really appreciate that you're helping me out here. Thank you in advance! (New to this stuff so I'm kind of needy :))

  • Like 1
Link to comment
Share on other sites


And I added a row to my "hook" table called CMS with 1 length (with PhpMyAdmin of course) and I checked if it would be visible on the transplant page as you mentioned that it would be but it wasn't there. Or what is it supposed to be called? I searched only for the words "CMS and "MYCMSPAGE" in the listbox.

Really appreciate that you're helping me out here. Thank you in advance! (New to this stuff so I'm kind of needy :))


No problem, I'm still trying to learn prestashop "syntax", so atm. my helping skills are limited.
btw. I updated my first "guide" above. One important step was missing.

Anyway..
You have to fill all fields when adding new row to hook table (please take backup of your database before modifying sql;)

For example my cmshook row is displayed in my hook table like this

id: 54 ( this is important take the next available id from your hook table)
name: cmspagehook (registerHook function inside modules will be calling this one)
Title: CMS page "name" modules (displayed in the transplant module list & module positions list)
Description: CMS page "name" modules (displayed in the module positions list)
Position: 0 ( I assume this will define is the module positionable or not, if 0 it will be hidden by the default in module positions view )


ps... Why I have a feeling that you have added new column to your hook table not a row?
Link to comment
Share on other sites


And I added a row to my "hook" table called CMS with 1 length (with PhpMyAdmin of course) and I checked if it would be visible on the transplant page as you mentioned that it would be but it wasn't there. Or what is it supposed to be called? I searched only for the words "CMS and "MYCMSPAGE" in the listbox.

Really appreciate that you're helping me out here. Thank you in advance! (New to this stuff so I'm kind of needy :))


No problem, I'm still trying to learn prestashop "syntax", so atm. my helping skills are limited.
btw. I updated my first "guide" above. One important step was missing.

Anyway..
You have to fill all fields when adding new row to hook table (please take backup of your database before modifying sql;)

For example my cmshook row is displayed in my hook table like this

id: 54 ( this is important take the next available id from your hook table)
name: cmspagehook (registerHook function inside modules will be calling this one)
Title: CMS page "name" modules (displayed in the transplant module list & module positions list)
Description: CMS page "name" modules (displayed in the module positions list)
Position: 0 ( I assume this will define is the module positionable or not, if 0 it will be hidden by the default in module positions view )


ps... Why I have a feeling that you have added new column to your hook table not a row?


Thanks I'll do those steps now.

Also reply to your PS:

Because I did add a new column (stupid me), you probably got that feeling because I said "I added a row called MYCMSPAGE"

*facepalms*
Link to comment
Share on other sites

hi guys,

Firstly I would like to thank you all for this thread, today I was wondering if there was a way to add a module to one of the CMS pages in prestashop and I came across this thread so followed the instructions but still have no success yet,

I was attempting to add the jgalleryview2 module to a cms page i wanted to name as "Archive" so I followed the instructions mentioned in the above posts which i am mentioning below:

1. I added a new row to the ps_hook table and named the id_hook, name, title, description, fields as "archive" , Position=1

2. Added these lines in the cms.tpl

{/if}
{if $cms->link_rewrite == 'ARCHIVE' }
{$HOOK_ARCHIVE}
{/if}



3. In the CMS.php file I added the follows

$smarty->assign(array(
       'cms' => $cms,
       'HOOK_ARCHIVE' => Module::hookExec('archive'), // Custom hook for mycmspage
       'content_only' => intval(Tools::getValue('content_only'))
   ));
   $smarty->display(_PS_THEME_DIR_.'cms.tpl'); 




4. I transplanted the jgalleryview2 block to the newly created hooks.

5. I added the below mentioned lines to the jgalleryview2.php file within the jgalleryview2 folder.

public function install()
   {
       if (!parent::install()
               OR !$this->registerHook('home')
               OR !$this->registerHook('header')
               OR !$this->registerHook('archive')
           )
           return false;
       return true;
   }




function hookHeader($params)
   {
       return $this->display(__FILE__, 'header.tpl');
   }

   function hookarchive($params)
   {
       return $this->display(__FILE__, 'cms.tpl');
   }

   function hookhome($params)
   {
       if ($xml = $this->_xml)
       {
           global $cookie, $smarty;
           $smarty->assign(array(
               'xml' => $xml,
               'title' => 'title_'.$cookie->id_lang,
               'text' => 'text_'.$cookie->id_lang
           ));
           return $this->display(__FILE__, $this->name.'.tpl');
       }
       return false;
   }



yet the Archive page does not display anything, Pointers on where I am goofing up or skipping anything would be highly appreciated.

Thank you !!

Link to comment
Share on other sites

hi guys,

yet the Archive page does not display anything, Pointers on where I am goofing up or skipping anything would be highly appreciated.

Thank you !!


Hi!

You have included cms.tpl file in here. Do you really have contents in that tpl file?

  function hookarchive($params)
   {
       return $this->display(__FILE__, 'cms.tpl');
   }

Link to comment
Share on other sites

You have included cms.tpl file in here. Do you really have contents in that tpl file?


No I do not have any content in there, as I was under the impression that cms.tpl is a default page for all pages that you create through the CMS and it was already there is the default prestashop theme folder, hence as I mentioned I have just created a blank cms page with the title as "Archive" and also added the friendly url as "archive" however I have left the page content as blank, I also tried adding the newly created hook to the content field in HTML mode but got nothing so far.

@codemj thank you for your quick response but I still am stuck up.
Link to comment
Share on other sites

The module you want to hook is that jgalleryxxx and you ahve created correctly the hook function inside that php file.
The cms.tpl file you are calling inside the jgallryxx.php file should be found inside that modules folder.

I can see that you your module have 2 other functions which does the actual action for your module..

Replace

function hookarchive($params)
   {
       return $this->display(__FILE__, 'cms.tpl');
   }



with

   function hookarchive($params)
   {
       if ($xml = $this->_xml)
       {
           global $cookie, $smarty;
           $smarty->assign(array(
               'xml' => $xml,
               'title' => 'title_'.$cookie->id_lang,
               'text' => 'text_'.$cookie->id_lang
           ));
           return $this->display(__FILE__, $this->name.'.tpl');
       }
       return false;
   } 



and try again.

If the module is not shown on your archive page check that friendlyname which you defined at CMS.

In cms.tpl file you defined {if $cms->link_rewrite == 'ARCHIVE'} make sure that in backoffice your archive cms page and check that your friendly url is in correct case (if its archive then your if clause won't match because you have defined ARCHIVE as condition..)

If it does not work test it with blank text so define

function hookarchive {

return "this is my test cmshook";

}

Link to comment
Share on other sites

@codemj I highly appreciate your patience in trying to help me understand, I got the module to appear on the archive cms page

Firstly, I added the function mentioned in your earlier post in the jgalleryview2.php then followed your step in which you suggested me to check the friendly url that i had set for the Archive CMS page, that was actually set to "archive" so I just matched the case in the cms.tpl file within my theme dir and the module started to show but not as intended but this post really helped me learn an important issue that any client could demand.

Hope the moderators mark this post as useful.

Thank you very much @codemj

Link to comment
Share on other sites

The module appears but it is not able to get the template meant to display the gallery, there are two tpl files within the jgalleryview2 folder header.tpl , jgalleryview2.tpl and in the jgalleryview2.php I added this function as per your instructions

function hookarchive($params)
   {
       if ($xml = $this->_xml)
       {
           global $cookie, $smarty;
           $smarty->assign(array(
               'xml' => $xml,
               'title' => 'title_'.$cookie->id_lang,
               'text' => 'text_'.$cookie->id_lang
           ));
           return $this->display(__FILE__, $this->name.'.tpl');
       }
       return false;
   } 



just below:

function hookheader($params)
   {
       return $this->display(__FILE__, 'header.tpl');
   }

   function hookhome($params)
   {
       if ($xml = $this->_xml)
       {
           global $cookie, $smarty;
           $smarty->assign(array(
               'xml' => $xml,
               'title' => 'title_'.$cookie->id_lang,
               'text' => 'text_'.$cookie->id_lang
           ));
           return $this->display(__FILE__, $this->name.'.tpl');
       }
       return false;
   }



The above function displays the gallery properly on the homepage, where this module was originally meant to display the gallery, but in the Archive cms page the gallery displays just like a unordered list minus the template , so i tried adding the template name to the function you had suggested me to mention like this

function hookarchive($params)
   {
       if ($xml = $this->_xml)
       {
           global $cookie, $smarty;
           $smarty->assign(array(
               'xml' => $xml,
               'title' => 'title_'.$cookie->id_lang,
               'text' => 'text_'.$cookie->id_lang
           ));
           return $this->display(__FILE__, 'jgalleryview2.tpl');
       }
       return false;
   } 



But this does not even bring the images but gives a message no template found, This makes it certain that the gallery that is hooked on the archive cms page is not getting the template. I know I am very close to what I am trying to achieve, but I am new to smarty template , hope you could point me in the right direction.

Thank you

Link to comment
Share on other sites

Like i said before the gallery displays properly on the homepage, so now i have narrowed down the cause of the gallery not showing up after i commented out the below mentioned function

/*    function hookheader($params)
   {
       return $this->display(__FILE__, 'header.tpl');
   }*/

   function hookhome($params)
   {
       if ($xml = $this->_xml)
       {
           global $cookie, $smarty;
           $smarty->assign(array(
               'xml' => $xml,
               'title' => 'title_'.$cookie->id_lang,
               'text' => 'text_'.$cookie->id_lang
           ));
           return $this->display(__FILE__, $this->name.'.tpl');
       }
       return false;
   }



On doing so the gallery that was showing properly on the homepage shows just like of that on the Archive CMS page. the header.tpl file in the module folder includes the jquery and gallery.css files for this module on commenting removes the styling for the gallery on the homepage, so i am wondering now on how the header.tpl file can be included for the gallery to be displayed properly on the archive cms page.

Link to comment
Share on other sites

Hi @codemj,

I am still stuck on how to get this gallery to work on the Archive page, the header.tpl file within the jgalleryview2 module folder has the css, jquery files included, and somehow these are not being included on the gallery block appearing on the Archive CMS page, was wondering how this header.tpl would be included to display the gallery properly on the Archive page.

Thanks in advance.

Link to comment
Share on other sites

Sorry I don't have much time for investigation your problem but I try something. Does your gallery module disapear totally from archive page if you uncomment that hookheader function?

It is really necessery to get that js and css stuff to the header and you should not have any problem if you uncomment hookheader?

I believe you should compare sourcecode of the gallery @ home page versus sourcecode @ archive page, there might be somedifferences so the stylesheets will be broken...

It might cause something like this @homepage






and in your archive page it might be something like





And if the module calls css classes for eg. div#homepage.your-module but your archive page stylesheet is something.. div#cms-page.your-module.. jquery with css etc.. looks usually inside the source code css classes etc..
Link to comment
Share on other sites

Hi @codemj,

The gallery does not disappear on the Archive page if I uncomment the function, the gallery stays but without the style on the Archive page. The only problem is that the gallery that is hooked on the Archive cms page dispays without the style.

Also i have attached the screen-shot image of the gallery as it appears on the Homepage and also as it appears on the archive page to give a clear picture on whats going on.

So I just wanted to know how to include the css and jquery files that are included in the header.tpl file in the modules folder, into the cms.tpl where we have created the hook in the code below:

{if !$content_only}
   {capture name=path}{l s=$cms->meta_title}{/capture}
   {include file=$tpl_dir./breadcrumb.tpl}
{/if}
{if $cms}

       {$cms->content}

{else}
   {l s='This page does not exist.'}
{/if}


{if !$content_only}

{l s='Home'}
{/if}
{if $cms->link_rewrite == 'archive' }
{$HOOK_ARCHIVE}
{/if} 



On some other posts I found a way to include the header.tpl file that is within the module dir

{include file=$tpl_dir./modules/jgalleryview2/header.tpl}



But I am unsure where I need to add this.


Thanks for replying @codemj

35150_wdXA7FzmFVaAGFFI9m5N_t

35151_1mVjAUZ0bgtvQQigWiyO_t

Link to comment
Share on other sites

  • 10 months later...
  • 4 weeks later...

@codemj

 

How do you do any of this with the new releases taken into account. I need to place a JQuery slideshow into a CMS page or the header information of a subcategory. I hope somebody's still viewing this thread as it's obvious you're boss at the coding side of this.

 

Thanks in advance

Link to comment
Share on other sites

  • 1 year later...

Hi @codemj

 

Am using PS 1.5.3.1

 

I want hook a module which already installed in home page and i have duplicated the module uploaded into the modules directory.

 

I followed exactly the same steps mentioned here in this post as followes

 

#1. Created a hook entry in PS_Hook table (HOOK_DESIGNMYSHIRT)

 

#2. In cms.tpl file from Module/Mymodule/cms.tpl i added the following

 

{if ($cms->link_rewrite == 'designmyshirt')}

{$HOOK_DESIGHNMYSHIRT}

{/if}

 

#3. Im cms.php file from the root directory i added the following

 

 

$smarty->assign(array(

'cms' => $cms,

'HOOK_DESIGHNMYSHIRT' => Module::hookExec('designmyshirt'), // Custom hook for mycmspage

'content_only' => intval(Tools::getValue('content_only'))

));

$smarty->display(_PS_THEME_DIR_.'cms.tpl');

 

#4. In the modules folder the module php file mymodule.php i added the following

 

public function install(){

if (parent::install() && $this->registerHook('HOOK_DESIGHNMYSHIRT'))

 

 

after at the end of this same file i added the below function

 

function hookdesignmyshirt($params)

{

if ($xml = $this->_xml)

{

global $cookie, $smarty;

$smarty->assign(array(

'xml' => $xml,

'title' => 'title_'.$cookie->id_lang,

'text' => 'text_'.$cookie->id_lang

));

return $this->display(__FILE__, $this->cms.'.tpl');

}

return false;

}

 

After this i installed the module and checked in the BO position. the module is displayed in the hook in BO

When i check the CMS page nothing is displayed even if i configure the module from BO.

 

I checked the Apache error log i get this following error

 

Notice: Undefined index: HOOK_DESIGHNMYSHIRT in G:\\WAMP Server\\wamp\\www\\rave\\cache\\smarty\\compile\\e2fae568d255bdaa47e61a9405a623865dd4d436.file.cms.tpl.php on line 40, referer: http://localhost/rave/kalai/index.php?controller=AdminCmsContent&token=4b15a61cf16e9ba9b70f78b7d317be98

 

I want this module to be placed in center of the CMS page...

 

Have i did everything correctly please help me to solve this issue....

 

 

Thanks....

Link to comment
Share on other sites

  • 1 year later...

Hello @date, Hello @codemj, hello to all,

@DATE

I have exactly the same with the "jgalleryView2" module. and I'm presta1.6.0.6.

The module is properly displayed on the home page. But the element list on the CMS pages exactly as your attachments.

How did you manage to solve this problem if you succeded in doing so?

Thank you in advance for your help

 

Hi @codemj,

The gallery does not disappear on the Archive page if I uncomment the function, the gallery stays but without the style on the Archive page. The only problem is that the gallery that is hooked on the Archive cms page dispays without the style.

Also i have attached the screen-shot image of the gallery as it appears on the Homepage and also as it appears on the archive page to give a clear picture on whats going on.

So I just wanted to know how to include the css and jquery files that are included in the header.tpl file in the modules folder, into the cms.tpl where we have created the hook in the code below:
 

{if !$content_only}    {capture name=path}{l s=$cms->meta_title}{/capture}    {include file=$tpl_dir./breadcrumb.tpl}{/if}{if $cms}    <div class="rte{if $content_only} content_only{/if}">        {$cms->content}    </div>{else}    {l s='This page does not exist.'}{/if}
{if !$content_only}    <p><a href="{$base_dir}" title="{l s='Home'}"><img src="{$img_dir}icon/home.gif" alt="{l s='Home'}" class="icon"></a><a href="{$base_dir}" title="{l s='Home'}">{l s='Home'}</a></p>{/if}{if $cms->link_rewrite == 'archive' }{$HOOK_ARCHIVE}{/if}

On some other posts I found a way to include the header.tpl file that is within the module dir
{include file=$tpl_dir./modules/jgalleryview2/header.tpl}

But I am unsure where I need to add this.


Thanks for replying @codemj

 

 

@codemj and other developers

 

Any idea? a method to solve this problem?
Again thank you for your help

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...