I came across a post on the Prestshop forum recently that was discussing how to display the contents of a single module on a page. The example proposed worked, but it seems to me that it worked only through sheer luck rather than design as all that was being done was to display a smarty .tpl file. The smarty variables required for the module used in the example were all included as global values, so it worked, but most other modules would need to be able to execute their underlying hook code in order to display anything meaningful.
For those who would like the flexibility of adding the contents of a module anywhere they like regardless of Prestashop’s hook locations, here’s how I propose it should be done:
Note that this will only work on a page that has correctly included the necessary Prestashop core code (/config/config.inc.php at a minimum, plus either the standard header.php or init.php depending on whether you wish to display the output in a standard page or not).
As an aside to the above, it’s also possible to implement any additional public member function in a module class definition and then call it using the above code ($hookFunction being the full name of the function to be called). This is handy should you wish to write modules that could for example also include some code to be executed externally via cron.
A full example that generates some output follows, although note that there’s no css included, so it may not look too pretty! It can be called anything, but should be uploaded to the root folder of your store in order to allow it to find the include files.
View the original article here
Get Ready-Made Niche Buyer Keyword Maps Every Month Plus Instant Access to Shopping Sites Analyzer Software
Niciun comentariu:
Trimiteți un comentariu