SlideShare a Scribd company logo
How we Started with eZ publish 5 a Real Use Case
How we started with eZ Publish 5
A real use case
A cookbook for successful migration from eZ4to theSymfonystack
Ekkehard Dörre - Coolscreen
Donat Fritschy - Webmanufaktur
Presenters
#ezsummer
Ekke is a consultant with deep knowledge in eZ Publish 4 and 5, eZ Find /
Apache Solr and with a faible for coming cutting edge web technologies. He is
one of the organizers of the PHP Unconference since seven years.
Donat is owner of Webmanufaktur, a full service web agency in Switzerland.
He works as projects manager, software architect and developer and likes
thinking outside of the box.
Members of CJW Network
·
·
·
3/35
Why a Cookbook?
#ezsummer
eZ Publish 5 allows for a smooth migration of eZ legacy projects to the
Symfony stack, permitting them to profit from the exiting new possibilities
However, it is a completely new beast
This workshop presents some basic recipes for beginners
·
·
·
4/35
Agenda
Things we'll cover:
#ezsummer
eZ 5 Installation
Building our first Bundle
Overriding the Page Layout Template
Integrating old Templates
Overriding Content Type (formerly Class) Templates
Overriding Field Type (formerly Attribute) Templates
One more thing...
·
·
·
·
·
·
·
5/35
Installation
Prepare the ingredients...
eZ 5 Installation
Recipe #1: Use the installation package
#ezsummer
Use the installation packages from share.ez.no
These are consistent and tested
Everybody knows about what you speak
Forking from GitHub is great, if you want and are able to contribute
·
·
·
·
7/35
eZ 5 Installation
Recipe #2: Read the Installation notes
Common Pitfalls:
#ezsummer
eZ 5 is a complex install and different from what you know
Actually, it combines to environments
https://confluence.ez.no/display/EZP/Requirements
https://confluence.ez.no/display/EZP/Normal+installation
·
·
Symfony
eZ Publish legacy (eZ 4.7)
-
-
·
·
Linking the assets
Directory and file permissions
·
·
8/35
eZ 5 Installation
Recipe #3: Get directory and file permissions right
Strategy 1 (quick and dirty)
Strategy 2
#ezsummer
Same user/group for web server and console user·
Separate users for web server and console user
Both members of www group
Usually requires umask( 0007 )
https://confluence.ez.no/x/9YBx
http://symfony.com/doc/current/book/installation.html#configuration-and-
setup
·
·
·
·
·
9/35
eZ 5 Installation
Recipe #4: Use the setup wizard
#ezsummer
This will give you a testable environment...
... which will immediately show you all problems ;-)
http://ezpublish.ezsc/
http://ezpublish.ezsc/ezdemo_site_admin
Login: admin / Password: ezsc
·
·
·
·
·
10/35
eZ 5 Installation
Recipe #5: The console is you friend
Check out the console command! First, log into the virtual machine using SSH
To list all available commands use
The most important commands:
#ezsummer
$ ssh ezsc@vm.ezsc
ezsc@vm.ezsc''s password: ezsc
$ cd /var/www/ezpublish
BASH
$ php ezpublish/console BASH
$ php ezpublish/console cache:clear
$ php ezpublish/console assets:install
$ php ezpublish/console assetic:dump
$ php ezpublish/console twig:lint
BASH
11/35
Creating Bundles
bring to the boil...
Creating a Bundle
Recipe #6: Use bundles for your sites
A Bundle is similar to an eZ extension and module. We suggest you create separate 'site' bundles for all
sites and 'functional' bundles for common components.
Creation of a bundle is easy:
Follow suggested Namespace conventions: YourCompany/YourCustomer/ComponentBundle
(CjwNetwork/SummerCamp2013/CookBookBundle)
You may define a shorted name for your bundle, as we have: CjwCookBookBundle
Create the Bundle in the src folder and answer yes to all questions.
Note: this will also change ezpublish/EzPublishKernel.php and ezpublish/config/routing.yml to
reference the generated bundle.
#ezsummer
$ php ezpublish/console generate:bundle BASH
13/35
Testing Your Bundle
A generated bundle contains sample code that allows for easy testing:
http://ezpublish.ezsc/hello/demo
The magic is done through a controller which receives the request from the router and prepares a
response with the help of a template renderer.
src/CjwNetwork/SummerCamp2013/CookBookBundle/Controller/DefaultController.php
Note: when implementing your own controllers, follow the code in eZDemoBundle as it includes
additional classes for accessing the repository.
#ezsummer
class DefaultController extends Controller
{
public function indexAction($name)
{
return $this->render('CjwCookBookBundle:Default:index.html.twig', array('name' => $name));
}
}
PHP
14/35
Inspecting the TWIG Template
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/Default/index.html.twig
We add some formatting and apply a TWIG filter:
#ezsummer
Hello {{ name}} TWIG
<h1>Hello and good morning {{ name | upper }}!</h1> TWIG
http://ezpublish.ezsc/hello/demo
TWIG Doc http://twig.sensiolabs.org/doc/filters/upper.html
·
·
15/35
Adding a Page Layout
Unlike eZ Publish legacy, TWIG templates work “bottom up” and support inheritance.
Therefore it’s easy to show the output in the standard eZ Demo Layout:
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/Default/index.html.twig
#ezsummer
{# This template extends pagelayout.html.twig and just replaces the 'content' block #}
{% extends "eZDemoBundle::pagelayout.html.twig" %}
{% block content %}
<h1>Hello and good morning {{ name | upper }}!</h1>
{% endblock %}
TWIG
16/35
Overriding Standard Templates
Dish up...
Creating a TWIG Template for Article
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/full/article.html.twig
#ezsummer
{% extends noLayout ? viewbaseLayout : "eZDemoBundle::pagelayout.html.twig" %}
{% block content %}
{# render a simple field #}
<h3>{{ ez_render_field( content, "title" ) }}</h3>
{# add a class attribute #}
{{ ez_render_field(
content,
"short_title",
{
'attr': { 'class': 'foobar' }
}
) }}
{# add an id to uniquely address this element #}
{{ ez_render_field(
content,
"author",
{
'attr': { 'id': 'authors' }
}
) }}
{{ ez_render_field( content, "intro" ) }}
{{ ez_render_field( content, "body" ) }}
{% endblock %}
TWIG
18/35
Configuration Settings
Recipe #7: Define Settings in your Bundle using Prepend
Besides the global configuration settings in ezpublish/config/ezpublish.yml there are other
possibilities to define settings:
https://confluence.ez.no/display/EZP/Import+settings+from+a+bundle
We prefer the one which allows the settings to be “prepended” to the normal settings, as no changes to
the global settings are needed.
Note: when implementing your own controllers, follow the code in eZDemoBundle as it includes
additional classes for accessing the repository.
#ezsummer 19/35
Configuration Settings
Recipe #7: Define Settings in your Bundle using Prepend
src/CjwNetwork/SummerCamp2013/CookBookBundle/DependencyInjection/CjwCookBookExtension.php
#ezsummer
use SymfonyComponentDependencyInjectionContainerBuilder;
use SymfonyComponentConfigFileLocator;
use SymfonyComponentDependencyInjectionExtensionPrependExtensionInterface;
use SymfonyComponentHttpKernelDependencyInjectionExtension;
use SymfonyComponentDependencyInjectionLoader;
use SymfonyComponentYamlYaml;
class CjwCookBookExtension extends Extension implements PrependExtensionInterface
public function prepend( ContainerBuilder $container )
{
// Loading our YAML file containing our template rules
$config = Yaml::parse( __DIR__ . '/../Resources/config/override.yml' );
// We explicitly prepend loaded configuration for "ezpublish" namespace.
// So it will be placed under the "ezpublish" configuration key, like in ezpublish.yml.
$container->prependExtensionConfig( 'ezpublish', $config );
}
PHP
20/35
Override Settings
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/config/override.yml
#ezsummer
# We explicitly prepend config for "ezpublish" namespace in service container extension,
# so no need to repeat it here
system:
ezdemo_site:
location_view:
full:
article_test:
template: "CjwCookBookBundle:full:article.html.twig"
match:
IdentifierContentType: article
YML
21/35
Change the Field Type Template ezauthor …
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/fields/field_templates.html.twig
#ezsummer
{# you must inherit from this template in order to use the block() functions !#}
{% extends "EzPublishCoreBundle::content_fields.html.twig" %}
{% block ezauthor_field %}
{% spaceless %}
{% if field.value.authors|length() > 0 %}
<ul {{ block( 'field_attributes' ) }}>
{% for author in field.value.authors %}
<li><a href="mailto:{{ author.email|escape( 'url' ) }}">xx {{ author.name }} xx</a></li>
{% endfor %}
</ul>
{% endif %}
{% endspaceless %}
{% endblock %}
TWIG
22/35
… and the Field Type Template ezdatetime
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/fields/field_templates.html.twig
#ezsummer
{% block ezdatetime_field %}
{% spaceless %}
{% if field.value.value %}
{% if fieldSettings.useSeconds %}
{% set field_value = field.value.value|localizeddate( 'short', 'medium', parameters.locale ) %}
{% else %}
{% set field_value = field.value.value|localizeddate( 'short', 'short', parameters.locale ) %}
{% endif %}
xx {{ block( 'simple_block_field' ) }} xx
{% endif %}
{% endspaceless %}
{% endblock %}
TWIG
23/35
Override Settings for Field Types
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/config/override.yml
#ezsummer
# We explicitly prepend config for "ezpublish" namespace in service container extension,
# so no need to repeat it here
system:
ezdemo_site:
location_view:
full:
article_test:
template: "CjwCookBookBundle:full:article.html.twig"
match:
IdentifierContentType: article
field_templates:
-
template: "CjwCookBookBundle:fields:field_templates.html.twig"
# Priority is optional (default is 0). The higher it is, the higher your template gets in the list.
priority: 10
YML
24/35
A Brand New Page Layout
… and enjoy!
Adding a New Page Layout for Our TWIG Article
We have prepared a brand new page layout in our bundle. You can find it at
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/pagelayout.html.twig
To use it, change
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/full/article.html.twig
to reference it:
Now articles (only!) are shown using the new page layout.
Note: to set the page layout for all your site, adjust the settings in ezpublish/config/parameters.yml
#ezsummer
{% extends noLayout ? viewbaseLayout : "CjwCookBookBundle::pagelayout.html.twig" %} TWIG
26/35
Some More Goodies
any sweets?
Set the Missing HTML Title
In eZDemoBundle the page title is not correctly set. {{ title|default( 'Home' ) }} is empty, so we
need to set it. We look for the legacy path, then for new eZ Publish content and the for our own bundle.
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/pagelayout.html.twig
https://confluence.ez.no/display/EZP/Twig+Helper
#ezsummer
{% if ezpublish.legacy.has( 'path' ) %}
{% set path = ezpublish.legacy.get( 'path' ) %}
{% set title %}
CJW Network {% for pathitem in path|reverse %} / {{ pathitem.text }}{% endfor %}
{% endset %}
{% elseif content is defined%}
{% set title %}
CJW Network / {{ content.contentInfo.name }} / (location ID is #{{ location.id }})
{% endset %}
{% else %}
{% set title %}
CJW Network / {{ name | capitalize }}
{% endset %}
{% endif %}
TWIG
28/35
Include an Old eZ Publish Template (.tpl)
To include an old eZ Template, e.g.
ezpublish_legacy/extension/ezdemo/design/ezdemo/templates/footer/latest_news.tpl into your
TWIG page layout, use the following code:
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/pagelayout.html.twig
#ezsummer
{% block latest_news %}
{% include "design:footer/latest_news.tpl" %}
{% endblock %}
TWIG
29/35
Include an Old eZ Publish Template (.tpl)
You can also pass parameters to an old template: change the fetch in
ezpublish_legacy/extension/ezdemo/design/ezdemo/templates/footer/latest_news.tpl
to ( 'content', 'tree', hash( 'parent_node_id', $parent_node_id, … )
and set the variable {$parent_node_id} in your TWIG page layout
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/pagelayout.html.twig
#ezsummer
{% block latest_news %}
{% include "design:footer/latest_news.tpl" with {"parent_node_id": 2} %}
{% endblock %}
TWIG
30/35
Override Several Blocks of the Page Layout
You can override several blocks of the TWIG page layout in a template that inherits from it.
src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/full/article.html.twig
https://confluence.ez.no/display/EZP/Legacy+code+and+features#Legacycodeandfeatures-
LegacyTemplateinclusion
#ezsummer
{% block latest_news %}
We set the content here for the latest_news block in our page layout
{% endblock %}
{% block content %}
...
{% endblock %}
TWIG
31/35
One More Thing...
Globally Overriding Resources!
Recipe #8: Override resources from bundles using the
ezpublish/Resource folder
Symfony allows for globally overrides of resources. You can teach eZ Publish the
same trick!
Suppose you want to override the eZDemo page layout:
#ezsummer
In the ezpublish folder, create a Resources folder
Replicate the directory structure for the elements you want to override
e.g. Resources/eZDemoBundle/views - use the correct bundle name!!!
Place your files there
·
·
·
·
33/35
Resources
To install our cookbook
Find the slides and the bash script to recreate the steps in
CjwNetwork/SummerCamp2013/CookBookBundle/Resources/doc
#ezsummer
cd /src
git clone https://github.com/dfritschy/cjw-cookbook.git CjwNetwork
BASH
34/35
<Thank You!>
Ekkehard Dörre
http://share.ez.no/community/profile/7431
@ekkeD
http://www.coolscreen.de
Donat Fritschy
https://github.com/dfritschy
http://share.ez.no/community/profile/10451
@webmanufaktur
http://www.webmanufaktur.ch

More Related Content

PDF
eZ UnConference#2 - eZ Publish 5 basics Philippe Vincent-Royol & Florent Huck
PDF
Learnings from Real eZ Publish 5 Projects
PDF
eZ Publish Platform 5.4 public webinar
PDF
How to start with eZ Publish 5
PPT
eZ Publish & Deployment of a multi-site platform
PDF
Symfony and eZ Publish
PDF
Web performances : Is It not the right time to (re)consider CMS ?
PDF
Remote Control WordPress
eZ UnConference#2 - eZ Publish 5 basics Philippe Vincent-Royol & Florent Huck
Learnings from Real eZ Publish 5 Projects
eZ Publish Platform 5.4 public webinar
How to start with eZ Publish 5
eZ Publish & Deployment of a multi-site platform
Symfony and eZ Publish
Web performances : Is It not the right time to (re)consider CMS ?
Remote Control WordPress

What's hot (20)

PDF
Ezobject wrapper workshop
PDF
Ansible 2.2
PDF
Symfony and eZ Publish: boarding now!
PDF
Ansible + WordPress
PPTX
6 Years of Docker: The Good, the Bad and Python Packaging at PyCon.DE&PyData ...
PDF
Stress Free Deployment - Confoo 2011
PDF
Setting up your Multi Engine Environment - Apache Railo and ColdFusion
PDF
Ansible automation tool with modules
PDF
Puppet for SysAdmins
PDF
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
PDF
Vagrant for real (codemotion rome 2016)
PDF
Docker presentasjon java bin
PDF
Virtual CD4PE Workshop
PDF
Learn Puppet : Quest Guide for the Learning VM
PDF
Symfony4 - Deep dive
PDF
How to deploy PHP projects with docker
PDF
Debugging webOS applications
PDF
Create your own composer package
PPTX
Performance tips for Symfony2 & PHP
PDF
Create Development and Production Environments with Vagrant
Ezobject wrapper workshop
Ansible 2.2
Symfony and eZ Publish: boarding now!
Ansible + WordPress
6 Years of Docker: The Good, the Bad and Python Packaging at PyCon.DE&PyData ...
Stress Free Deployment - Confoo 2011
Setting up your Multi Engine Environment - Apache Railo and ColdFusion
Ansible automation tool with modules
Puppet for SysAdmins
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Vagrant for real (codemotion rome 2016)
Docker presentasjon java bin
Virtual CD4PE Workshop
Learn Puppet : Quest Guide for the Learning VM
Symfony4 - Deep dive
How to deploy PHP projects with docker
Debugging webOS applications
Create your own composer package
Performance tips for Symfony2 & PHP
Create Development and Production Environments with Vagrant
Ad

Similar to How we Started with eZ publish 5 a Real Use Case (20)

PPTX
Migrating extensions to eZ Publish 5
PDF
2013.04.23 eZ Sessions 6 - Migrating legacy eZ Publish extensions - Lukasz Se...
PDF
Unleash your Symfony projects with eZ Platform
PDF
Ny symfony meetup may 2015
PDF
Create a Symfony Application from a Drupal Perspective
PDF
eZPublish meets Simfony2 - phpDay2013
PDF
eZ Publish 5 in depth inspection
PDF
Hands-on with the Symfony2 Framework
PDF
The Naked Bundle - Tryout
PDF
Fabien Potencier "Symfony 4 in action"
PDF
Twig tips and tricks
PDF
Symfony 4: A new way to develop applications #ipc19
KEY
Twig for Drupal @ Frontendunited Amsterdam 2012
PDF
eZ Publish 5: from zero to automated deployment (and no regressions!) in one ...
PDF
Boltc CMS - a really quick overview
PDF
Getting instantly up and running with Docker and Symfony
PDF
Efficient development workflows with composer
PDF
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
PPTX
Symfony2 for legacy app rejuvenation: the eZ Publish case study
PDF
Start with Bolt and Go Ez - eZ Publish Summer Camp 2015
Migrating extensions to eZ Publish 5
2013.04.23 eZ Sessions 6 - Migrating legacy eZ Publish extensions - Lukasz Se...
Unleash your Symfony projects with eZ Platform
Ny symfony meetup may 2015
Create a Symfony Application from a Drupal Perspective
eZPublish meets Simfony2 - phpDay2013
eZ Publish 5 in depth inspection
Hands-on with the Symfony2 Framework
The Naked Bundle - Tryout
Fabien Potencier "Symfony 4 in action"
Twig tips and tricks
Symfony 4: A new way to develop applications #ipc19
Twig for Drupal @ Frontendunited Amsterdam 2012
eZ Publish 5: from zero to automated deployment (and no regressions!) in one ...
Boltc CMS - a really quick overview
Getting instantly up and running with Docker and Symfony
Efficient development workflows with composer
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony2 for legacy app rejuvenation: the eZ Publish case study
Start with Bolt and Go Ez - eZ Publish Summer Camp 2015
Ad

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Spectroscopy.pptx food analysis technology
Encapsulation_ Review paper, used for researhc scholars
20250228 LYD VKU AI Blended-Learning.pptx
Spectral efficient network and resource selection model in 5G networks
Unlocking AI with Model Context Protocol (MCP)
MIND Revenue Release Quarter 2 2025 Press Release
Dropbox Q2 2025 Financial Results & Investor Presentation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Electronic commerce courselecture one. Pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Understanding_Digital_Forensics_Presentation.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Empathic Computing: Creating Shared Understanding
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Machine learning based COVID-19 study performance prediction
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectroscopy.pptx food analysis technology

How we Started with eZ publish 5 a Real Use Case

  • 2. How we started with eZ Publish 5 A real use case A cookbook for successful migration from eZ4to theSymfonystack Ekkehard Dörre - Coolscreen Donat Fritschy - Webmanufaktur
  • 3. Presenters #ezsummer Ekke is a consultant with deep knowledge in eZ Publish 4 and 5, eZ Find / Apache Solr and with a faible for coming cutting edge web technologies. He is one of the organizers of the PHP Unconference since seven years. Donat is owner of Webmanufaktur, a full service web agency in Switzerland. He works as projects manager, software architect and developer and likes thinking outside of the box. Members of CJW Network · · · 3/35
  • 4. Why a Cookbook? #ezsummer eZ Publish 5 allows for a smooth migration of eZ legacy projects to the Symfony stack, permitting them to profit from the exiting new possibilities However, it is a completely new beast This workshop presents some basic recipes for beginners · · · 4/35
  • 5. Agenda Things we'll cover: #ezsummer eZ 5 Installation Building our first Bundle Overriding the Page Layout Template Integrating old Templates Overriding Content Type (formerly Class) Templates Overriding Field Type (formerly Attribute) Templates One more thing... · · · · · · · 5/35
  • 7. eZ 5 Installation Recipe #1: Use the installation package #ezsummer Use the installation packages from share.ez.no These are consistent and tested Everybody knows about what you speak Forking from GitHub is great, if you want and are able to contribute · · · · 7/35
  • 8. eZ 5 Installation Recipe #2: Read the Installation notes Common Pitfalls: #ezsummer eZ 5 is a complex install and different from what you know Actually, it combines to environments https://confluence.ez.no/display/EZP/Requirements https://confluence.ez.no/display/EZP/Normal+installation · · Symfony eZ Publish legacy (eZ 4.7) - - · · Linking the assets Directory and file permissions · · 8/35
  • 9. eZ 5 Installation Recipe #3: Get directory and file permissions right Strategy 1 (quick and dirty) Strategy 2 #ezsummer Same user/group for web server and console user· Separate users for web server and console user Both members of www group Usually requires umask( 0007 ) https://confluence.ez.no/x/9YBx http://symfony.com/doc/current/book/installation.html#configuration-and- setup · · · · · 9/35
  • 10. eZ 5 Installation Recipe #4: Use the setup wizard #ezsummer This will give you a testable environment... ... which will immediately show you all problems ;-) http://ezpublish.ezsc/ http://ezpublish.ezsc/ezdemo_site_admin Login: admin / Password: ezsc · · · · · 10/35
  • 11. eZ 5 Installation Recipe #5: The console is you friend Check out the console command! First, log into the virtual machine using SSH To list all available commands use The most important commands: #ezsummer $ ssh ezsc@vm.ezsc ezsc@vm.ezsc''s password: ezsc $ cd /var/www/ezpublish BASH $ php ezpublish/console BASH $ php ezpublish/console cache:clear $ php ezpublish/console assets:install $ php ezpublish/console assetic:dump $ php ezpublish/console twig:lint BASH 11/35
  • 13. Creating a Bundle Recipe #6: Use bundles for your sites A Bundle is similar to an eZ extension and module. We suggest you create separate 'site' bundles for all sites and 'functional' bundles for common components. Creation of a bundle is easy: Follow suggested Namespace conventions: YourCompany/YourCustomer/ComponentBundle (CjwNetwork/SummerCamp2013/CookBookBundle) You may define a shorted name for your bundle, as we have: CjwCookBookBundle Create the Bundle in the src folder and answer yes to all questions. Note: this will also change ezpublish/EzPublishKernel.php and ezpublish/config/routing.yml to reference the generated bundle. #ezsummer $ php ezpublish/console generate:bundle BASH 13/35
  • 14. Testing Your Bundle A generated bundle contains sample code that allows for easy testing: http://ezpublish.ezsc/hello/demo The magic is done through a controller which receives the request from the router and prepares a response with the help of a template renderer. src/CjwNetwork/SummerCamp2013/CookBookBundle/Controller/DefaultController.php Note: when implementing your own controllers, follow the code in eZDemoBundle as it includes additional classes for accessing the repository. #ezsummer class DefaultController extends Controller { public function indexAction($name) { return $this->render('CjwCookBookBundle:Default:index.html.twig', array('name' => $name)); } } PHP 14/35
  • 15. Inspecting the TWIG Template src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/Default/index.html.twig We add some formatting and apply a TWIG filter: #ezsummer Hello {{ name}} TWIG <h1>Hello and good morning {{ name | upper }}!</h1> TWIG http://ezpublish.ezsc/hello/demo TWIG Doc http://twig.sensiolabs.org/doc/filters/upper.html · · 15/35
  • 16. Adding a Page Layout Unlike eZ Publish legacy, TWIG templates work “bottom up” and support inheritance. Therefore it’s easy to show the output in the standard eZ Demo Layout: src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/Default/index.html.twig #ezsummer {# This template extends pagelayout.html.twig and just replaces the 'content' block #} {% extends "eZDemoBundle::pagelayout.html.twig" %} {% block content %} <h1>Hello and good morning {{ name | upper }}!</h1> {% endblock %} TWIG 16/35
  • 18. Creating a TWIG Template for Article src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/full/article.html.twig #ezsummer {% extends noLayout ? viewbaseLayout : "eZDemoBundle::pagelayout.html.twig" %} {% block content %} {# render a simple field #} <h3>{{ ez_render_field( content, "title" ) }}</h3> {# add a class attribute #} {{ ez_render_field( content, "short_title", { 'attr': { 'class': 'foobar' } } ) }} {# add an id to uniquely address this element #} {{ ez_render_field( content, "author", { 'attr': { 'id': 'authors' } } ) }} {{ ez_render_field( content, "intro" ) }} {{ ez_render_field( content, "body" ) }} {% endblock %} TWIG 18/35
  • 19. Configuration Settings Recipe #7: Define Settings in your Bundle using Prepend Besides the global configuration settings in ezpublish/config/ezpublish.yml there are other possibilities to define settings: https://confluence.ez.no/display/EZP/Import+settings+from+a+bundle We prefer the one which allows the settings to be “prepended” to the normal settings, as no changes to the global settings are needed. Note: when implementing your own controllers, follow the code in eZDemoBundle as it includes additional classes for accessing the repository. #ezsummer 19/35
  • 20. Configuration Settings Recipe #7: Define Settings in your Bundle using Prepend src/CjwNetwork/SummerCamp2013/CookBookBundle/DependencyInjection/CjwCookBookExtension.php #ezsummer use SymfonyComponentDependencyInjectionContainerBuilder; use SymfonyComponentConfigFileLocator; use SymfonyComponentDependencyInjectionExtensionPrependExtensionInterface; use SymfonyComponentHttpKernelDependencyInjectionExtension; use SymfonyComponentDependencyInjectionLoader; use SymfonyComponentYamlYaml; class CjwCookBookExtension extends Extension implements PrependExtensionInterface public function prepend( ContainerBuilder $container ) { // Loading our YAML file containing our template rules $config = Yaml::parse( __DIR__ . '/../Resources/config/override.yml' ); // We explicitly prepend loaded configuration for "ezpublish" namespace. // So it will be placed under the "ezpublish" configuration key, like in ezpublish.yml. $container->prependExtensionConfig( 'ezpublish', $config ); } PHP 20/35
  • 21. Override Settings src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/config/override.yml #ezsummer # We explicitly prepend config for "ezpublish" namespace in service container extension, # so no need to repeat it here system: ezdemo_site: location_view: full: article_test: template: "CjwCookBookBundle:full:article.html.twig" match: IdentifierContentType: article YML 21/35
  • 22. Change the Field Type Template ezauthor … src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/fields/field_templates.html.twig #ezsummer {# you must inherit from this template in order to use the block() functions !#} {% extends "EzPublishCoreBundle::content_fields.html.twig" %} {% block ezauthor_field %} {% spaceless %} {% if field.value.authors|length() > 0 %} <ul {{ block( 'field_attributes' ) }}> {% for author in field.value.authors %} <li><a href="mailto:{{ author.email|escape( 'url' ) }}">xx {{ author.name }} xx</a></li> {% endfor %} </ul> {% endif %} {% endspaceless %} {% endblock %} TWIG 22/35
  • 23. … and the Field Type Template ezdatetime src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/fields/field_templates.html.twig #ezsummer {% block ezdatetime_field %} {% spaceless %} {% if field.value.value %} {% if fieldSettings.useSeconds %} {% set field_value = field.value.value|localizeddate( 'short', 'medium', parameters.locale ) %} {% else %} {% set field_value = field.value.value|localizeddate( 'short', 'short', parameters.locale ) %} {% endif %} xx {{ block( 'simple_block_field' ) }} xx {% endif %} {% endspaceless %} {% endblock %} TWIG 23/35
  • 24. Override Settings for Field Types src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/config/override.yml #ezsummer # We explicitly prepend config for "ezpublish" namespace in service container extension, # so no need to repeat it here system: ezdemo_site: location_view: full: article_test: template: "CjwCookBookBundle:full:article.html.twig" match: IdentifierContentType: article field_templates: - template: "CjwCookBookBundle:fields:field_templates.html.twig" # Priority is optional (default is 0). The higher it is, the higher your template gets in the list. priority: 10 YML 24/35
  • 25. A Brand New Page Layout … and enjoy!
  • 26. Adding a New Page Layout for Our TWIG Article We have prepared a brand new page layout in our bundle. You can find it at src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/pagelayout.html.twig To use it, change src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/full/article.html.twig to reference it: Now articles (only!) are shown using the new page layout. Note: to set the page layout for all your site, adjust the settings in ezpublish/config/parameters.yml #ezsummer {% extends noLayout ? viewbaseLayout : "CjwCookBookBundle::pagelayout.html.twig" %} TWIG 26/35
  • 28. Set the Missing HTML Title In eZDemoBundle the page title is not correctly set. {{ title|default( 'Home' ) }} is empty, so we need to set it. We look for the legacy path, then for new eZ Publish content and the for our own bundle. src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/pagelayout.html.twig https://confluence.ez.no/display/EZP/Twig+Helper #ezsummer {% if ezpublish.legacy.has( 'path' ) %} {% set path = ezpublish.legacy.get( 'path' ) %} {% set title %} CJW Network {% for pathitem in path|reverse %} / {{ pathitem.text }}{% endfor %} {% endset %} {% elseif content is defined%} {% set title %} CJW Network / {{ content.contentInfo.name }} / (location ID is #{{ location.id }}) {% endset %} {% else %} {% set title %} CJW Network / {{ name | capitalize }} {% endset %} {% endif %} TWIG 28/35
  • 29. Include an Old eZ Publish Template (.tpl) To include an old eZ Template, e.g. ezpublish_legacy/extension/ezdemo/design/ezdemo/templates/footer/latest_news.tpl into your TWIG page layout, use the following code: src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/pagelayout.html.twig #ezsummer {% block latest_news %} {% include "design:footer/latest_news.tpl" %} {% endblock %} TWIG 29/35
  • 30. Include an Old eZ Publish Template (.tpl) You can also pass parameters to an old template: change the fetch in ezpublish_legacy/extension/ezdemo/design/ezdemo/templates/footer/latest_news.tpl to ( 'content', 'tree', hash( 'parent_node_id', $parent_node_id, … ) and set the variable {$parent_node_id} in your TWIG page layout src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/pagelayout.html.twig #ezsummer {% block latest_news %} {% include "design:footer/latest_news.tpl" with {"parent_node_id": 2} %} {% endblock %} TWIG 30/35
  • 31. Override Several Blocks of the Page Layout You can override several blocks of the TWIG page layout in a template that inherits from it. src/CjwNetwork/SummerCamp2013/CookBookBundle/Resources/views/full/article.html.twig https://confluence.ez.no/display/EZP/Legacy+code+and+features#Legacycodeandfeatures- LegacyTemplateinclusion #ezsummer {% block latest_news %} We set the content here for the latest_news block in our page layout {% endblock %} {% block content %} ... {% endblock %} TWIG 31/35
  • 33. Globally Overriding Resources! Recipe #8: Override resources from bundles using the ezpublish/Resource folder Symfony allows for globally overrides of resources. You can teach eZ Publish the same trick! Suppose you want to override the eZDemo page layout: #ezsummer In the ezpublish folder, create a Resources folder Replicate the directory structure for the elements you want to override e.g. Resources/eZDemoBundle/views - use the correct bundle name!!! Place your files there · · · · 33/35
  • 34. Resources To install our cookbook Find the slides and the bash script to recreate the steps in CjwNetwork/SummerCamp2013/CookBookBundle/Resources/doc #ezsummer cd /src git clone https://github.com/dfritschy/cjw-cookbook.git CjwNetwork BASH 34/35
  • 35. <Thank You!> Ekkehard Dörre http://share.ez.no/community/profile/7431 @ekkeD http://www.coolscreen.de Donat Fritschy https://github.com/dfritschy http://share.ez.no/community/profile/10451 @webmanufaktur http://www.webmanufaktur.ch