Jump to content

Attaching a module to a CMS page.


Recommended Posts

Hi all,

 

I've been developing a module that shows a form and then some information depending on the input. This should appear only on a particular page on the website.

 

I decided to to use a CMS page and a custom hook. I am not sure if the approach is correct, because I can't get it to work every time. Here is what I do:

 

I go to the theme's CMS template (root/themes/myTheme/cms.tpl) and find the following lines:

<div class="rte{if $content_only} content_only{/if}">
    {$cms->content}
</div>

Immediately before that I add:

{if !$content_only} 
    {hook h='customCMS'}
{/if}

I also create a CMS page manually. In my module I register the hook so that the module is attached to it. There is also a restriction that the module content only appears on the selected CMS page. In modules->positions I can see that the hook exists in the db and the module is attached to it. I've put some debug lines in the beginning of the code implementing the hook and I don't see them executed in the cases when the module doesn't work.

 

I've tested this on different installations of Prestashop:

Local XAMPP server, ps version 1.6.1.6 - worked at first but doesn't work after changing the theme and reverting back to the default one.

Remote server, ps version 1.6.1.5 - works well. No major changes were made.

Remote server, ps version 1.6.1.6  - didn't work at first. A week later it works without any major changes to the website.

 

As you can see the behavior is very unreliable. Is this the right way to approach this issue. I would assume attaching module functionality to a page in the website is something common with Prestashop developers. What is the correct approach.

 

Thanks,

Dimitar

Link to comment
Share on other sites

Maybe to try 


{hook h='customCMS' mod='your_module_name'}

http://doc.prestashop.com/display/PS16/Managing+Hooks

 

Also if you change theme you must edit that theme also so not optimal.

 

Maybe to think other way around. You would get more control and not theme

depending if you create specific module page with controller. And in that page 

attach content of specific CMS page or just have one more text area field in

modules back office so you can add custom HTML there.

Link to comment
Share on other sites

Thanks for your reply!

 

I've changed the approach based on your suggestion. I've created module specific page with a controller. The content of this page is displayed with a smarty template. I don't need a CMS page now.

 

On my page I have a from. When this form is submitted I want the page to change. I have a function in my module that takes input and sends data to the template so that the new information is displayed. But I can't access this function from my controller.

 

Here is some code from the controller

if (Tools::isSubmit('form'))
{
$param1 = trim(Tools::getValue('param1'));
$param2 = trim(Tools::getValue('param2'));
// myFunc is a function in the module class
myFunc($param1, $param2);
}

So how does one call a module function from the controller?

 

EDIT: I just saw I didn't update this post when I found the solution. So in case someone needs this:

you have to add $this->module-> before the function you want to call. So in the example above it would be

$this->module->myFunc($param1, $param2);
Edited by dimitar-lwc (see edit history)
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...