- PrestaShop Module Development
- Fabien Serny
- 382字
- 2021-08-05 17:12:26
Adding the module configuration
We will now add configuration options to our module. To do so, we just have to add the getContent
function to our module. The return value of this function will be the content displayed on your screen.
In our case, we will write the following code:
public function getContent() { return 'My name is Raphael, I am a tourist'; }
Note
The sentence returned is only an example (and a private joke from one of the PrestaShop core developers).
When the getContent
function is placed in a module's class, PrestaShop automatically displays a Configure link in the back office. When the Configure link is clicked, this function is called and the return value is displayed.
So, if you refresh the modules list in the back office and your module is installed, you should now see a Configure button:

If you click on the configuration link, you will see the translations block (automatically generated by PrestaShop software), and the sentence that we wrote in the function:

You must avoid writing HTML in PHP code (very bad practice). That's why we will use the Smarty template (the template engine used in PrestaShop). If you are not familiar with this library, or with template engines in general, I invite you to read the official documentation (the link is in the introduction of this book). However, do not panic; using Smarty templates is quite easy!
We will start by creating the templates
directory in the root of the module's directory: /views/templates/hook/
. All of the templates used in the module's class must be placed in this directory.
One of the best practices is to name the templates with the name of the method in which they are used. So, we will create a template named getContent.tpl
. Let's write our previous text in this template:
My name is Raphael, I am still a tourist
Then, in the getContent
method, we just have to change the return line to the following:
return $this->display(__FILE__, 'getContent.tpl');
In this case, the display
method will automatically use the getContent.tpl
template in the /views/templates/hook/
directory. If you refresh the page, you'll see that your display has changed (we added one word). Now, your view is separated from your code. The following screenshot displays the file architecture you should have now:

- 游戲運(yùn)營與出海實(shí)戰(zhàn):策略、方法與技巧
- 網(wǎng)上開店與創(chuàng)業(yè)
- 移動(dòng)互聯(lián)網(wǎng)時(shí)代
- 微店安裝、推廣、經(jīng)營、管理一本通
- 快手營銷138招:一本書教會你玩賺快手
- 一本書玩轉(zhuǎn)電商、微商軟文營銷
- 互聯(lián)網(wǎng)+跨界顛覆
- 短視頻+直播帶貨一本通:抖音+快手+B站+淘寶+拼多多
- 商業(yè)銀行操作風(fēng)險(xiǎn)管理實(shí)務(wù)
- 電子商務(wù)實(shí)驗(yàn)指導(dǎo)
- 電子商務(wù)產(chǎn)品質(zhì)量網(wǎng)絡(luò)輿情分析與管控理論
- 淘寶直播與電商新玩法
- 淘寶天貓網(wǎng)店實(shí)戰(zhàn)寶典
- 全渠道營銷:后電商時(shí)代新常態(tài)
- 引爆社群:移動(dòng)互聯(lián)網(wǎng)時(shí)代的新4C法則(第3版)