Now, we can create our extension called packtmedia
. First, we will open our favorite file manager and then inside the eZ Publish installation folder, we will open the extension
folder. In this folder, create an empty folder named packtmedia
.
# cd /var/www/packtmediaproject
# cd extension/
# mkdir packtmedia
We'll use this extension to create a new design, some template operators, and our custom translations. We can now prepare the directory structure that will serve us in storing our code.
First, we have to create the settings
folder that serves to override the standard configuration files (those named *. ini.append
) and, in particular, the site.ini.append.php
and template.ini.append.php
files that help to enable our design, operators, and translations.
We can create this folder by executing the following commands from the installation folder of eZ Publish:
To create a design extension, we need to create a folder named design
in our extension
folder, after which we will create another folder, with a custom name, inside this. This last folder will be the container for our files. We will call this folder magazine
, and inside it we will create the following folders:
images
: This will contain all of the layout image files (*.jpg, *.gif, *.png
, and so on)stylesheets
: This will contain all of the stylesheet files (*.css
)javascript
: It will contain all of the JavaScript files (*.js
)templates
: This will contain all of the custom templates that will override the standard design (*.tpl
)override
: This will contain all of the override class templates (*.tpl
)To create these folders, we have to execute the following commands from the root folder of the eZ Publish installation:
# cd /var/www/packtmediaproject/extension
# cd packtmedia
# mkdir design
# cd design
# mkdir magazine
# cd magazine
# mkdir images stylesheets javascript templates override
# cd override
# mkdir templates
# cd /var/www/packtmediaproject/extension/packtmedia
In the end, the extension folder's structure should be created in this way:
packtmediaproject/extension/packtmedia/design/
magazine/
images/
javascript/
override/
templates/
stylesheets/
templates/
Next, we need to add the following code to the design.ini.append.php
file, which is inside the settings
folder of our packtmedia
extension, so that the system automatically loads our design:
<? /* #?ini charset="utf-8"? [ExtensionSettings] DesignExtensions[]=packtmedia */ ?>
It is possible to create a custom design without an extension by just copying the packtmediaproject/extension/packtmedia/design/magazine
folder into the packtmediaproject/design
folder. Subsequently, it will just upload the new layout in the site.ini.append.php
file of our siteaccess. The extension design is well suited to easily reusing a design in other sites, or for re-selling the layout. Not creating the extension means using an ad hoc layout for a single project, which is unlikely to be reused.
To create a new extension for new template operators, we need to create the autoloads
and the classes
folders. In these folders, we will place the PHP classes that will be used by our scripts.
As before, to apply these changes, we will execute the following code from the root installation of eZ Publish:
# cd /var/www/packtmediaproject/extension/packtmedia
# mkdir autoloads
# mkdir classes
Next, let's create the eztemplateautoload.php
file which will be used to automatically load the template operators in the autoloads
folder, executing the following commands:
# cd autoloads
# touch eztemplateautoload.php
Next, we have to write the following code inside the eztemplateautoload.php
file:
<?php $eZTemplateOperatorArray = array(); ?>
Next, we need to add the following code to the site.ini.append.php
file, which is inside the settings
folder of our packtmedia
extension, so that system automatically loads our template operators:
<?php /* #?ini charset="utf-8"? ... [TemplateSettings] ExtensionAutoloadPath[]=packtmedia ... */ ?>
We will see how to create the PHP code for a new template operator in the next chapter.
The next extension that we will set up will be the translation extension. This will help us manage new languages in our layout. First, we need to create the translations
folder. Inside this folder, we can create a folder for each language that we want to translate. In our case, it will be the fre-FR, ita-IT
, and de-DE
folders because we want to translate it to Italian, German, and French.
Open a shell and then execute the following commands:
# cd /var/www/packtmediaproject/extension/packtmedia
# mkdir translations
# cd translations
# mkdir ita-IT
# mkdir fre-FR
# mkdir de-DE
For simplicity, from now on, we will see only one of the installed languages; you can create (or edit) the others in the same way.
Next, inside the ita-IT
folder, we have to create the translations.ts
file executing the following commands:
# cd ita-IT
# touch translation.ts
In addition to this, we have to add the following code to the newly translation.ts
file created before, using our preferred IDE:
<!DOCTYPE TS><TS> <context> <name></name> <message> <source></source> <translation></translation> </message> </context> </TS>
This XML snippet is a standard placeholder for the translations that we'll see and use in the next chapters. As seen for the previous extensions, we need to add the following code to the site.ini.append.php
file, inside the settings
folder of the packtmedia
extension, to make sure that the translations file is automatically loaded:
Open the file from an IDE, and then add the new TranslationExtensions
value after the RegionalSettings
settings, as shown:
3.17.157.6