Monday 18 April 2011 2:42:34 pm
We will create an extension to house our code in this tutorial so the code is isolated and can be easily used on multiple projects. Let’s create an extension called mynewsletter. If you call your extension something else be sure to rename all code samples which use the extension name.
This extension will store the custom views we create and also the custom module we build.
We will firstly ensure eZ Publish looks within our extension for the custom modules we create. At the same time, we also need to tell it the name of the modules which exist in our extension This offers us the potential to create multiple modules within the same extension however in our case we will just need to create one, which I have named as “newsletter”. The module name we provide here will be used in the URL whenever we are dealing with the module.
Create a file named extension/mynewsletter/settings/module.ini.append.php and add the following content:
<?php /* [ModuleSettings] ExtensionRepositories[]=mynewsletter ModuleList[]=newsletter */ ?>
There are a couple of lines of code here and each are equally important.
To ensure the templates we create in our extension (as well as any specific CSS or images you are storing in the extension ) are retrieved we need to ensure the design folder is included when templates are searched for. We do this by creating another settings file in the settings directory called design.ini.append.php (extension/mynewsletter/settings/design.ini.append.php). Create the file and add the following code:
<?php /* [ExtensionSettings] DesignExtensions[]=mynewsletter */ ?>
The final part of setting up the extension is ensuring the extension itself is active. Navigate to /settings/override from the root of your eZ Publish site. In this directory there should be a file called site.ini.append.php. If no file exists, create it now and then open it. Enter the following settings underneath the settings which already exist, if any :
<?php /* #?ini charset="iso-8859-1"? … [ExtensionSettings] ActiveExtensions[]=mynewsletter */ ?>
Note: If you already have an ExtensionSettings element in the file, simply add the ActiveExtensions line rather than duplicating the whole block.
Now that we have setup the extension we are ready to create our module.