Jump to content

How can show my module in a newly created custom hook ?


Iron giant

Recommended Posts

Anyone please help me on this issue

 

I have a module suppose its called "mymodule".

I want to show the module content on a unique position, i.e prestashop already provided many types of hooks, but other than this

I want to create new unique hook which will placed into a unique position and in that unique position, i want to show my module content.

 

please help me guys.

 

Thank you

Link to comment
Share on other sites

hello

for example, you created hook with name:

dispalyMyPosition

 

then your module must have function:

 

public function hook displayMyPosition($params){

//do something

}

 

 

remember to transplant module to this hook under modules > positions tab

  • Like 1
Link to comment
Share on other sites

Hello vekia,

thanks for the reply.

I have just created a banner module. but i dont know how to create a hook. I have followed many tutorials. but couldn't get success on this.

 

Can you tell me step by step process for this issue?

1) how to create hook

2) how to create unique position  for it , which will be available whenever my module will be installed.

 

 

i have written mydsiplayposition in my module.

 

but have not create any hook called mydisplayposition, because i dont know. i am really stuck on it.

 and i guess i have to write for example in tpl file {$HOOK_myposition} also.

I am confused.

 

please help me.

 

 thank you

 

 

Link to comment
Share on other sites

hello

 

you have to register a hook first in your module's install function

 

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

 

Then you eill have to define that hooks

 

function hookHeader($params)
    {
        $result = '';
        $result .= $this->_addCss('css/'.$this->name.'.css');
        $result .= $this->_addJs('js/min.js');
        $result .= $this->_addJs('js/pack.js');
        return $result;
    }

    function hookFooter($params)
    {
        return $this->display(__FILE__, 'views/templates/hook/'.$this->name.'.tpl');;
    }

 

Now install your module and configure it. Click on manage hook at the top right corner. then click on transplant a module.

Select your module name from the drop down list of module then select displayFooter (Footer) as hook into because you have registered footer hook in your module and in the definition you have rendered the view file of your module in the footer hook. then click on save button you can see your module in footer.

Link to comment
Share on other sites

hello,

Thanks

but in your post you have written all predefined hooks or position.

But in my case i want to create a new position (i.e. a custom hook for my website) where i can set any module of mine or can set any downloaded module in that custom position.

 

Thanks

Link to comment
Share on other sites

hello vekia,

Thanks for the reply

 I just want my hooks to show in the drop down modules-> positions

Hook which is created by me and suppose it will show on footer area.

I can set any module in that position using the custom hook from (modules-> positions )which is created by me.

 

i just want to create a proper hook like prestashop already have predefined (displayRight, displayLeft etc etc).

for example my hook will be called  "mydisplayposition", which can selected from modules->positions in admin panel.

 

I just want my module or any module to show in my created positions, not in predefined positions which prestashop provided already.

 

Thanks

Link to comment
Share on other sites

Step 1 : Open PphMyAdmin .find your shop database and open it.

 

in prestashop you need to create one Row in "ps_hook" table. 

 

 

first open ps_hook table and Insert new Row and name it for example displayTop2 .

 

 

you just need to fill name and title field's.not any other values needed.

Link to comment
Share on other sites

hello vekia,

 

i have insert a new row in the ps_hook table "displayTop2"

 

and what are the steps afterwards ?

 

suppose i have to show the editorial module content in this position  "displayTop2". so what to do now?

in the module editorial . i have wriitent the following . in the editorial.php

 

public function hookdisplayTop2()
    {
        echo "HELLO WORLD";
       
    }

 

and i have to see this in footer.tpl

 

so in footer.tpl i have wrote this

{$HOOK_TOP2}

 

 but couldn't get anything

 

Please help.

thanks

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

hi guys,

I am new in module development.

 

how to add javascript in head section of pristashop 1.7

 

I need to add following code in head                         

 

<script src="https://clientcdn.pushchant.com/core/rp.js"></script> <script>
_pe.subscribe();
</script>

 

and tell me how to add service worker in root of prestashop directory using module

 

http://stackoverflow.com/questions/42595508/how-to-add-script-in-head-section-of-prestashop

Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...

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...