The override system

The override system is able to load different kinds of content node views instead of the standard view, based on defined rules.

Creating a template override

In our project, we can override the standard views for the following standard and custom classes:

  • Class Profile with full, line, and embed views
  • Class Folder for the "Issue Year" section with a full view
  • Class Folder for the "Issues" section with thumb, full, line, and embed views
  • Class Folder for the "Issue Archive" section with full and embed views
  • Class Article with full, line, and embed views

Usually, the full view is used to view a content node with all of its attributes. (We can think of a full content node view as a static HTML page of that element.) The line view is used to view the content node in a list, for example, if we want to see all articles published in a given year. The embed view is used if we want to attach a content node to another content node description attribute.

To create our override rules, we can use an automatic method through the graphic eZ Publish interface, or we can add rules manually to the override.ini.append.php file of each siteaccess where we want to render the custom view instead of the standard view.

Creating a template override from a graphic interface

Through the graphical interface of eZ Publish, you can create rules in the override.ini file. Unfortunately, this interface is very limited and not very usable, which is why we prefer to create rules and files manually. The limitations of creating rules through the interface are many. First of all, you cannot specify all of the rules allowed by the file that is being overridden, and it is also not possible to structure the override files into a well-ordered folder tree. All files are placed inside the override templates of our design extension. If we override many files, you will appreciate that it becomes very difficult to maintain the folder order.

Let's see one example of how you can create an override of the class folder for the section with ID 6, which corresponds to our Issue archive. In the next section, we'll see in detail how to manually create all of the template overrides along with their rules.

To create a new override rule, we need to log into the site backend and fill the user login form with our credentials.

Creating a template override from a graphic interface

Next, we need to select the Design tab on the top menu, and then click on the Template link in the leftmost menu.

Now we are on the page where we can see a list of all system templates and override templates. Below this, we can also see a list of the Most common templates.

Creating a template override from a graphic interface

We want to override the content node view, full, for the Folder class. So, we must click on /node/view/full.tpl in the Most common templates list.

Creating a template override from a graphic interface

The page that is now loaded, has all the template override rule settings for the standard template /node/view/full.tpl. To create a new template, we need to click on the New override button at the bottom of the list.

Creating a template override from a graphic interface

The page that is loaded has a form in which we have to specify the following information:

  • Filename (the system suggests specifying an explanatory name)
  • Class for which we are adding this override
  • Section for which we are doing this override
  • Node ID, if the override is only for a specific content node

We also need to choose if we want to create an Empty file, a copy of the original standard template, a container, or a simple view.

In our situation, we name the file full_folder_issuearchive.tpl. We select the Folder class and the Archive section, as created in the previous chapter, to manage this rule. At the end, we choose to create an Empty file, and then click on the OK button. Now our override rule and file are created.

Creating a template override from a graphic interface

A new override rule is always put at the end of the rule list. The system loads the first file where the rules match the context. So for this override, we have to increase the priority value from 35 to 1. To do this, we have to change the value in the form field, which is in the column before the edit button, and click on the Update priorities button.

By clicking on the Edit button, it is possible to modify the template source code. If we have a template (it could be an idea) with very complex code inside it, it could be impossible to manage the template with this feature because the textarea does not support code highlight and indentation. It would be better to use our favorite IDE to edit it.

As you can see, the automatic override mechanism is not simple to use. We recommend that you manually create the rules and provide order to the files in your override folder.

Creating a template override manually

As we want to create custom views only for the frontend siteaccess, we need to change the override.ini.append.php file within the settings folder for all of our siteaccesses:

  • /var/www/packtmediaproject/settings/siteaccess/ezwebin_site/override.ini.append.php
  • /var/www/packtmediaproject/settings/siteaccess/ita/override.ini.append.php
  • /var/www/packtmediaproject/settings/siteaccess/eng/override.ini.append.php
  • /var/www/packtmediaproject/settings/siteaccess/fre/override.ini.append.php
  • /var/www/packtmediaproject/settings/siteaccess/dev/ override.ini.append.php
  • /var/www/packtmediaproject/settings/siteaccess/staging/ override.ini.append.php"

Because the file will always be the same for all four siteaccess, it would be useful to change only one, for example the siteaccess ezwebin_site file, and then create a symbolic link to the master file within the other three siteaccess.


# cd /var/www/packtmediaproject/settings/siteaccess
# rm -r ita/override.ini.append.php eng/override.ini.append.php fre/ override.ini.append.php dev/override.ini.append.php staging/override.ini.append.php
# ln -s ezwebin_site/override.ini.append.php ita/
# ln -s ezwebin_site/override.ini.append.php eng/
# ln -s ezwebin_site/override.ini.append.php fre/
# ln -s ezwebin_site/override.ini.append.php dev/
#ln -s ezwebin_site/override.ini.append.php staging/"

Profile class

We will write the following rule in the file to create the full view for the Profile class:

[profile_full]
Source=node/view/full.tpl
MatchFile=full/profile.tpl
Subdir=templates
Match[class_identifier]=editor_profile

We will write the following rule in the file under the [profile_full] rule to create the line view for the Profile class:

[profile_line]
Source=node/view/line.tpl
MatchFile=line/profile.tpl
Subdir=templates
Match[class_identifier]=editor_profile

We will write the following rule under the [profile_line] rule in the file to create the embed view for the Profile class:

[profile_embed]
Source=node/view/embed.tpl
MatchFile=embed/profile.tpl
Subdir=templates Match[class_identifier]=editor_profile

The section name should be unique within the override.ini.append.php file. The Source is the position in which the source file that we want to override is placed. The MatchFile is the location where you will find our custom file, starting from Subdir, which is the subdirectory override folder from the extension of our design. For example, to view profile_full, we want to overwrite the standard file node/view/full.tpl with our file override templates/full/profile.tpl only if the identifier of the class is equal to profile.

Folder class for the issue year archive

We will write the following rule, under the [profile_embed] rule, in the file to create the full view for the folder class in the issue year archive:

[folder_issueyear]
Source=node/view/full.tpl
MatchFile=full/folder_issueyear.tpl
Subdir=templates
Match[class_identifier]=folder
Match[section]=6
Match[depth]=3

Folder class for issue

We will write the following rule, under the [folder_issueyear] rule, in the file to create the full view for the folder class and render our issue page:

[folder_issue_full]
Source=node/view/full.tpl
MatchFile=full/folder_issue.tpl
Subdir=templates
Match[class_identifier]=folder
Match[parent_class]=folder
Match[section]=6
Match[depth]=4

We will write the following rule, under the [folder_issue_full] rule, in the file to create the line view for the folder class and render our issue page:

[folder_issue_line]
Source=node/view/line.tpl
MatchFile=line/folder_issue.tpl
Subdir=templates
Match[class_identifier]=folder
Match[parent_class]=folder
Match[section]=6
Match[depth]=4

We will write the following rule, under the [folder_issue_line] rule, in the file to create the embed view for the folder class and render our issue page:

[folder_issue_embed]
Source=node/view/embed.tpl
MatchFile=embed/folder_issue.tpl
Subdir=templates
Match[class_identifier]=folder
Match[parent_class]=folder
Match[section]=6
Match[depth]=4

We will write the following rule, under the [folder_issue_embed] rule, in the file to create the thumb view for the folder class and render our issue page:

[folder_issue_thumb]
Source=node/view/thumb.tpl
MatchFile=thumb/folder_issue.tpl
Subdir=templates
Match[class_identifier]=folder
Match[parent_class]=folder
Match[section]=6
Match[depth]=4

The Match[depth] rule matches the node with a depth equal to 4 in the content tree nodes.

Folder class for the issue archive section

We will write the following rule, under the [folder_issue_thumb] rule, in the file to create the full view for the folder class in the issue archive section:

[folder_issuearchive_full]
Source=node/view/full.tpl
MatchFile=full/folder_issuearchive.tpl
Subdir=templates Match[class_identifier]=folder
# the Archive id section created in the previuos chapter Match[section]=6

We will write the following rule, under the [folder_issuearchive_full] rule, in the file to create the embed view for the folder class in the issue archive section:

[folder_issuearchive_embed]
Source=node/view/embed.tpl
MatchFile=embed/folder_issuearchive.tpl
Subdir=templates
Match[class_identifier]=folder
Match[section]=6

Article class

We will write the following rule, under the [folder_issuearchive_embed] rule, in the file to create the full view for the article class and render the article items inside our issue:

[issue_article_full]
Source=node/view/full.tpl
MatchFile=full/issue_article.tpl
Subdir=templates
Match[class_identifier]=article
Match[section]=6

We will write the following rule, under the [issue_article_full] rule, in the file to create the line view for the article class:

[issue_article_line]
Source=node/view/line.tpl
MatchFile=line/issue_article.tpl
Subdir=templates
Match[class_identifier]=article
Match[section]=6

We will write the following rule, under the [issue_article_line] rule, in the file to create the embed view for the article class:

[issue_article_embed]
Source=node/view/embed.tpl
MatchFile=embed/issue_article.tpl
Subdir=templates
Match[class_identifier]=article
Match[section]=6

Frontpage embed object

For the home page, we'll use the standard class eZ Webin called FrontPage, which gives us the opportunity to have a layout with three columns. This also satisfies the needs of our mockup. Within the three columns, we need different types of boxes to represent:

  • The left column:
    • The latest news
  • The central column:
    • The latest issue
  • The right column:
    • The most important article for the week
    • The latest item from the forum

To create these boxes, we'll use the standard eZ Webin templates to embed objects using the existing override. This can be activated by selecting the correct class for the embed object.

To meet our needs, we must modify the following two files for the extension eZ Webin:

  • extension/ezwebin/desing/ezwebin/override/templates/embed/vertically_listed_sub_items.tpl
  • extension/ezwebin/desing/ezwebin/override/templates/itemizedsubitems/folder.tpl

We must copy them into our extension in the same location.

Creating our custom template file

Finally, we must create our custom files for each rule of the override:

# cd /var/www/packtmediaproject/extension/packtmedia/design/magazine/override/templates
# mkdir full line embed thumb itemizedsubitems
# touch full/profile.tpl line/profile.tpl embed/profile.tpl
# touch full/folder_issuearchive.tpl embed/folder_issuearchive.tpl
# touch full/folder_issue.tpl line/folder_issue.tpl embed/folder_issue.tpl thumb/folder_issue.tpl
# touch full/issue_article.tpl line/issue_article.tpl embed/issue_article.tpl
# touch full/feedbackform.tpl
# cp ../../../../ezwebin/design/ezwebin/override/templates/embed/vertically_listed_sub_items.tpl embed/
#cp ../../../../ezwebin/desing/ezwebin/override/templates/itemizedsubitems/folder.tpl itemizedsubitems

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.251.163