Giter Club home page Giter Club logo

Comments (12)

Xsmael avatar Xsmael commented on May 28, 2024 1

Thank you for your patience with me.

Acutally, I dont want to create a new module, but to set a hook in the theme, that i can see in the back office and place an existing module there.

from docs.

PierreRambaud avatar PierreRambaud commented on May 28, 2024

Hi,

You must have a look on https://devdocs.prestashop.com/1.7/modules/concepts/hooks/
Hooks are register with install method. If you add new hooks after installed your module, you need to reset it :)

Regards

from docs.

Xsmael avatar Xsmael commented on May 28, 2024

In the manual they showed two way to create hooks:

From a regular PHP file:
Hook::exec('MyCustomHook');

or
From a Smarty template:
{hook h='MyCustomHook'}

I choose the later for simplicity but it didnt work

from docs.

PierreRambaud avatar PierreRambaud commented on May 28, 2024

It's not to create Hook, it call a registered hook.
The wording is not clear, but your are looking for Theme hook.

The procedure is :

  • Create a module
  • Add some hook with registerHook during install() process. (Register Hook)
    • if something wrong, uninstall and install module again
  • Add methods corresponding to the selected hook. (Execute hook)

If you create a custom theme and want to add a custom hook for example MyAwesomeDesign:

<div>
  {hook h='MyAwesomeDesign'}
</div>

You must have this in your module:

    public function install()
    {
        return parent::install() && $this->registerHook('MyAwesomeDesign');
    }

   public function hookMyAwesomeDesign()
   {
        // Something I want to do while calling 'MyAwesomeDesign' hook in my theme
   }

Hope I help you =)

from docs.

PierreRambaud avatar PierreRambaud commented on May 28, 2024

No probleme, I'm here to help you :)

The only way to register a hook in database is to have a module which use the registerHook function.
Without module, a hook is useless, in my previous example, hook is called with hookMyAwesomeDesign. So if you create a hook without module, it will never called.

Regards

from docs.

Xsmael avatar Xsmael commented on May 28, 2024

how about creating a new hook, for an existing module ?

from docs.

PierreRambaud avatar PierreRambaud commented on May 28, 2024

What do you mean? Adding a new hook in the core?

Otherwise all registered hooks are related to modules, you can add upgrade directories like this modules: https://github.com/PrestaShop/ps_customtext/tree/master/upgrade to register new hooks or write anything you want during upgrade :)

from docs.

PierreRambaud avatar PierreRambaud commented on May 28, 2024

Hey, just found this link https://devdocs.prestashop.com/1.7/modules/creation/enabling-auto-update/#adding-updating-modules-or-hooks-between-versions

from docs.

mickaelandrieu avatar mickaelandrieu commented on May 28, 2024

Hello @Xsmael,

as your questions have been answered I'm closing this.

Feel free to re-open or to open a new issue if you need helps.

from docs.

grzegorzgit avatar grzegorzgit commented on May 28, 2024

So you cannot create hook just in the template, so you could later position modules to it? Let's say I need two new hooks in product page, but without any specific module, just to have it in "positions" to attach there any module I want. Isn't the theme.yml file for it? If not, then what is the purpose of registering hook in the theme.yml?

from docs.

kpodemski avatar kpodemski commented on May 28, 2024

@grzegorzgit you can indeed register new hooks and modules to it, but if module doesn't implement hook properly there's nothing to display

most of modules are treated as widgets maybe this helps you out a bit?

from docs.

Stolaweb avatar Stolaweb commented on May 28, 2024

I have the same problem. I want to register new hook and place in it module (already installed in my shop)

How to do that. I made custom hook in the theme.yml but I cant see it in Positions in the dashboard. How to make it visible to installed modules to move them to it?

from docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.