SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Use Symfony2 components inside WordPress

             (…and live happily)
Walter Dal Mut
   Cofounder at Corley S.r.l.
   First level degree Electronic Engineering
   Ungraduated student of Computer Science




Maurizio Pelizzone
   Cofounfer at Mavida S.n.c
   WordPress Lover
Symfony2 is a reusable set of standalone,
decoupled, and cohesive PHP
components that solve common web
development problems

Fabien Potencier
http://fabien.potencier.org/article/49/what-is-symfony2
Use Composer autoload in your theme
WordPress & Monolog
Monolog is a logging library for PHP 5.3
used by Symfony2. It is inspired by the
Python LogBook library.
Get Monolog
Website: https://github.com/Seldaek/monolog

Using Monolog:
Create a new composer.json file

{
    "require": {
      "monolog/monolog": "1.1.*"
    }
}

curl -s http://getcomposer.org/installer | php
php composer.phar install
wrap inside WordPress…
… and use in your theme
WordPress & Assetic
Assetic is an asset management
framework for PHP.
Assetic is based on the Python webassets
library
Get Assetic
Website: https://github.com/kriswallsmith/assetic

Using Assetic:
Create a new composer.json file

{
    "require": {
      "kriswallsmith/assetic": "v1.0.4"
    }
}

curl -s http://getcomposer.org/installer | php
php composer.phar install
GOAL: Merge, Minimize and Compile all
javascript loaded through WordPress
Code example:
https://github.com/miziomon/symfonyday
WordPress & Twig
Twig: the flexible, fast, and secure
template engine for PHP.

Twig uses a syntax similar to the
Django and Jinja template
languages which inspired the Twig
runtime environment.
Why using a Template Engine ?
PHP doesn't support many features modern
template languages should have nowadays

       o Concision
       o Template oriented Syntax
       o Reusability
       o "Security" by default
                 I'll explain in the next slides
                 Read more on dedicated webpages.

Read more at: http://fabien.potencier.org/article/34/templating-engines-in-php
Concision
PHP                                                    TWIG

<?php echo $name ?>                                    {{name}}
<?php echo                                             {{name|escape}}
  htmlspecialchars(
  $name,
  ENT_QUOTES,
                                                       No short version it's
  'UTF-8')                                              already the short
?>
Short tags
                                                        version.
<?=$name?>
Using short tags could creates problems. You have to
    enable the short tags that are disabled by
    default.
Template oriented Syntax
PHP                                     TWIG

<?php if ($items): ?>                   {% for item in items %}
 <?php foreach ($items as $item): ?>     * {{ item }}
  * <?php echo $item ?>                 {% else %}
 <?php endforeach; ?>                    No item has been found.
<?php else: ?>                          {% endfor %}
 No item has been found. <?php endif;
   ?>
                                        It's more clear and use
                                           a new syntax.
Reusability
<!-- base.html -->                              <!-- index.html -->
<html                                           {% extends "base.html" %}
     xmlns="http://www.w3.org/1999/xhtml"
     xml:lang="en" lang="en">                   {% block head %}
 <head>                                          {{ block.super }}
  {% block head %}                               <link rel="stylesheet" href="main.css" />
    <link rel="stylesheet" href="main.css" />   {% endblock %}
  {% endblock %}
 </head>                                        {% block content %}
 <body>                                          Index content
  {% block content %}{% endblock %}             {% endblock %}
 </body>
</html>
Security
" I'm not saying PHP is not a secure language, far from it. But needless to say that
escaping a variable in a template is just a nightmare.

" Sometimes, security should be enabled by default, especially for templates written
by non-developers who are not necessarily aware of the common web threats like XSS
or CSRF.
                                                                              @fabpot

PHP                                            TWIG
                                               Output is escaped by default.
<?php echo
 htmlspecialchars(                             {% autoescape off %}
 $var,                                          {{ object.as_html }}
 ENT_QUOTES,                                   {% endautoescape %}
 'UTF-8') ?>
                                               I'm well aware of the automatic output
                                                   escaping problems.
Get Twig
Website: http://twig.sensiolabs.org
Twig C Extensions: https://github.com/derickr/twig-ext.git

Using composer:
Create a new composer.json file

{
    "require": {
      "twig/twig": "1.*"
    }
}

curl -s http://getcomposer.org/installer | php
php composer.phar install
Twig & WordPress
Using Twig into a wordpress plugin/theme could
  simplify and improve the development.

• Plugin development (views)
• Theme development
Integrating Twig into a Plugin
Just initialize Twig and use it. Using a static
  reference to share the Twig instance (simple
  way).

function get_twig()
{
  static $twig;
  if (!$twig) {
     $loader = new Twig_Loader_Filesystem(__DIR__ . '/templates');
     $twig = new Twig_Environment($loader, array('cache' => false));
  }

    return $twig;
}
Render a template
During the Twig initialization we specify the view
 location ("templates" folder). Now you can
 create a Twig view and save it. Into your plugin
 just link to it:

$template = get_twig()->loadTemplate('tweets.twig');
echo $template->render(array('elements' => $unpack));


In this example we load the "tweets.twig" view
  and pass the elements variable.
WP Plugin Example
You can checkout an example at:

•   https://github.com/wdalmut/wp-simple-tweets

In this example we add a widget into the admin dashboard that
   shows tweets of @CorleyCloud account.
Make a template using Twig
WordPress is designed to use PHP as template engine. We can force to integrate Twig
  as the default templating system. You can find an example of integration at:

https://github.com/wdalmut/wp-twig-theme

This example realize a simple blank template with some WP functionalities (sidebars,
    posts, pages, archives).
Making a Twig Proxy
WordPress uses a lot of functions to generate pieces of html. To
  speedup the Twig integration we can create a simple proxy
  that enable WP functions into a Twig template.

class TwigProxy {
    public function __call($function, $arguments) {
        if (!function_exists($function)) {
            throw new Exception("{$function} not
   exists.");
            return NULL;
        }
        return call_user_func_array($function,
   $arguments);
    }
}
Using the Twig Proxy
This proxy allows us to call WordPress functions
  into a view.

<div id="sidebar">
    {% if not wp.dynamic_sidebar("Sidebar Widgets") %}

    {{ wp.get_search_form }}
<!-- continue -->
</div>


"dynamic_sidebar" and
 "get_search_form" are WP functions.
Load Twig templates instead PHPs
We can use WordPress hooking system to override the default
  template loading.
•  add_filter
    o home_template
    o single_template
    o page_template
    o 404_template
    o archive_template
    o Etc, etc...
•  add_action
    o template_include
        Engage Twig and prepare data to view.
Layout management
Instead of use get_header and get_footer that break HTML we
   can use template inheritance of Twig.


{% extends "base.twig" %}

{% block title %}
  {{ parent() }} | Page Not Found
{% endblock %}

{% block content %}
<h2>Error 404 - Page Not Found</h2>
{% endblock %}
Enjoy with Twig
Twig is extremely simple and powerful, you can
  play and enjoy with this great template engine
  and get more power during your wp
  development.



                Have a nice day
?
Thank you!

             Walter Dal Mut
             walter.dalmut@gmail.com
             @wdalmut


             Maurizio Pelizzone
             maurizio@mavida.com
             @miziomon

Weitere ähnliche Inhalte

Was ist angesagt?

WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practicesmarkparolisi
 
How to Get Started Theming Plone
How to Get Started Theming PloneHow to Get Started Theming Plone
How to Get Started Theming Plonecdw9
 
WordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwaltenWordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwaltenWalter Ebert
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsDylan Jay
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress pluginAnthony Montalbano
 
Mehr Performance für WordPress - WordCamp Köln
Mehr Performance für WordPress - WordCamp KölnMehr Performance für WordPress - WordCamp Köln
Mehr Performance für WordPress - WordCamp KölnWalter Ebert
 
Doing Things the WordPress Way
Doing Things the WordPress WayDoing Things the WordPress Way
Doing Things the WordPress WayMatt Wiebe
 
Advanced Thesis Techniques and Tricks
Advanced Thesis Techniques and TricksAdvanced Thesis Techniques and Tricks
Advanced Thesis Techniques and TricksBrad Williams
 
Don't sh** in the Pool
Don't sh** in the PoolDon't sh** in the Pool
Don't sh** in the PoolChris Jean
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)Steve Souders
 
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...Otto Kekäläinen
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLIDiana Thompson
 
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachTake Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachDiana Thompson
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern ApproachAlessandro Fiore
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress PluginBrad Williams
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
Using composer with WordPress
Using composer with WordPressUsing composer with WordPress
Using composer with WordPressMicah Wood
 
State of the resource timing api
State of the resource timing apiState of the resource timing api
State of the resource timing apiAaron Peters
 

Was ist angesagt? (20)

WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
How to Get Started Theming Plone
How to Get Started Theming PloneHow to Get Started Theming Plone
How to Get Started Theming Plone
 
WordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwaltenWordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwalten
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
Mehr Performance für WordPress - WordCamp Köln
Mehr Performance für WordPress - WordCamp KölnMehr Performance für WordPress - WordCamp Köln
Mehr Performance für WordPress - WordCamp Köln
 
Doing Things the WordPress Way
Doing Things the WordPress WayDoing Things the WordPress Way
Doing Things the WordPress Way
 
Advanced Thesis Techniques and Tricks
Advanced Thesis Techniques and TricksAdvanced Thesis Techniques and Tricks
Advanced Thesis Techniques and Tricks
 
Don't sh** in the Pool
Don't sh** in the PoolDon't sh** in the Pool
Don't sh** in the Pool
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
 
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachTake Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long Beach
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern Approach
 
The wp config.php
The wp config.phpThe wp config.php
The wp config.php
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Using composer with WordPress
Using composer with WordPressUsing composer with WordPress
Using composer with WordPress
 
SocketStream
SocketStreamSocketStream
SocketStream
 
State of the resource timing api
State of the resource timing apiState of the resource timing api
State of the resource timing api
 

Ähnlich wie Use Symfony2 components inside WordPress

Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPFabien Potencier
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Rene Bakx
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Ted Kulp
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Hugo Hamon
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsDECK36
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress WebsitesKyle Cearley
 
Implement rich snippets in your webshop
Implement rich snippets in your webshopImplement rich snippets in your webshop
Implement rich snippets in your webshopArjen Miedema
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress developmentSteve Mortiboy
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigPHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigWake Liu
 
Various Ways of Using WordPress
Various Ways of Using WordPressVarious Ways of Using WordPress
Various Ways of Using WordPressNick La
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPressNile Flores
 
Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!Ryan Weaver
 
Twig Brief, Tips&Tricks
Twig Brief, Tips&TricksTwig Brief, Tips&Tricks
Twig Brief, Tips&TricksAndrei Burian
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flaskjuzten
 

Ähnlich wie Use Symfony2 components inside WordPress (20)

Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
Implement rich snippets in your webshop
Implement rich snippets in your webshopImplement rich snippets in your webshop
Implement rich snippets in your webshop
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigPHPConf-TW 2012 # Twig
PHPConf-TW 2012 # Twig
 
Various Ways of Using WordPress
Various Ways of Using WordPressVarious Ways of Using WordPress
Various Ways of Using WordPress
 
Seven deadly theming sins
Seven deadly theming sinsSeven deadly theming sins
Seven deadly theming sins
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
 
Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!
 
Revoke-Obfuscation
Revoke-ObfuscationRevoke-Obfuscation
Revoke-Obfuscation
 
Twig Brief, Tips&Tricks
Twig Brief, Tips&TricksTwig Brief, Tips&Tricks
Twig Brief, Tips&Tricks
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flask
 

Mehr von Maurizio Pelizzone

WordPress and his «almost» native page builder
WordPress and his «almost» native page builderWordPress and his «almost» native page builder
WordPress and his «almost» native page builderMaurizio Pelizzone
 
WCEU 2016 - 10 tips to sleep better at night
WCEU 2016 - 10 tips to sleep better at nightWCEU 2016 - 10 tips to sleep better at night
WCEU 2016 - 10 tips to sleep better at nightMaurizio Pelizzone
 
Professional WordPress Workflow - WPDay 2015
Professional WordPress Workflow - WPDay 2015 Professional WordPress Workflow - WPDay 2015
Professional WordPress Workflow - WPDay 2015 Maurizio Pelizzone
 
WordPress Meetup Torino Giugno 2015
WordPress Meetup Torino Giugno 2015WordPress Meetup Torino Giugno 2015
WordPress Meetup Torino Giugno 2015Maurizio Pelizzone
 
Wordpress e la gestione di progetti complessi
Wordpress e la gestione di progetti complessiWordpress e la gestione di progetti complessi
Wordpress e la gestione di progetti complessiMaurizio Pelizzone
 
WordPress: Smart Ideas for Startup - SMW torino 2012
WordPress: Smart Ideas for Startup - SMW  torino 2012 WordPress: Smart Ideas for Startup - SMW  torino 2012
WordPress: Smart Ideas for Startup - SMW torino 2012 Maurizio Pelizzone
 
Security and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress ConferenceSecurity and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress ConferenceMaurizio Pelizzone
 
WordPress for developers - phpday 2011
WordPress for developers -  phpday 2011WordPress for developers -  phpday 2011
WordPress for developers - phpday 2011Maurizio Pelizzone
 
Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]
 Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012] Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]
Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]Maurizio Pelizzone
 
Poliedric WordPress - Go!WebDesign
Poliedric WordPress - Go!WebDesignPoliedric WordPress - Go!WebDesign
Poliedric WordPress - Go!WebDesignMaurizio Pelizzone
 
Custom taxonomies / Custom post type - wordcamp milano 2010
Custom taxonomies / Custom post type - wordcamp milano 2010Custom taxonomies / Custom post type - wordcamp milano 2010
Custom taxonomies / Custom post type - wordcamp milano 2010Maurizio Pelizzone
 
Ottimizzare un sito web per i motori di ricerca
Ottimizzare un sito web per i motori di ricercaOttimizzare un sito web per i motori di ricerca
Ottimizzare un sito web per i motori di ricercaMaurizio Pelizzone
 
Come funzionano i template di Wordpress
Come funzionano i template di WordpressCome funzionano i template di Wordpress
Come funzionano i template di WordpressMaurizio Pelizzone
 

Mehr von Maurizio Pelizzone (17)

WordPress and his «almost» native page builder
WordPress and his «almost» native page builderWordPress and his «almost» native page builder
WordPress and his «almost» native page builder
 
WCEU 2016 - 10 tips to sleep better at night
WCEU 2016 - 10 tips to sleep better at nightWCEU 2016 - 10 tips to sleep better at night
WCEU 2016 - 10 tips to sleep better at night
 
Professional WordPress Workflow - WPDay 2015
Professional WordPress Workflow - WPDay 2015 Professional WordPress Workflow - WPDay 2015
Professional WordPress Workflow - WPDay 2015
 
WordPress Hardening v4
WordPress Hardening v4WordPress Hardening v4
WordPress Hardening v4
 
WordPress Meetup Torino Giugno 2015
WordPress Meetup Torino Giugno 2015WordPress Meetup Torino Giugno 2015
WordPress Meetup Torino Giugno 2015
 
Wordpress e la gestione di progetti complessi
Wordpress e la gestione di progetti complessiWordpress e la gestione di progetti complessi
Wordpress e la gestione di progetti complessi
 
WordPress Hardening
WordPress HardeningWordPress Hardening
WordPress Hardening
 
WordPress: Smart Ideas for Startup - SMW torino 2012
WordPress: Smart Ideas for Startup - SMW  torino 2012 WordPress: Smart Ideas for Startup - SMW  torino 2012
WordPress: Smart Ideas for Startup - SMW torino 2012
 
Security and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress ConferenceSecurity and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress Conference
 
WordPress for developers - phpday 2011
WordPress for developers -  phpday 2011WordPress for developers -  phpday 2011
WordPress for developers - phpday 2011
 
Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]
 Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012] Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]
Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]
 
Poliedric WordPress - Go!WebDesign
Poliedric WordPress - Go!WebDesignPoliedric WordPress - Go!WebDesign
Poliedric WordPress - Go!WebDesign
 
Wordpress 3.0 - Go!WebDesign
Wordpress 3.0 - Go!WebDesignWordpress 3.0 - Go!WebDesign
Wordpress 3.0 - Go!WebDesign
 
Custom taxonomies / Custom post type - wordcamp milano 2010
Custom taxonomies / Custom post type - wordcamp milano 2010Custom taxonomies / Custom post type - wordcamp milano 2010
Custom taxonomies / Custom post type - wordcamp milano 2010
 
Ottimizzare un sito web per i motori di ricerca
Ottimizzare un sito web per i motori di ricercaOttimizzare un sito web per i motori di ricerca
Ottimizzare un sito web per i motori di ricerca
 
Casa In Rete
Casa In ReteCasa In Rete
Casa In Rete
 
Come funzionano i template di Wordpress
Come funzionano i template di WordpressCome funzionano i template di Wordpress
Come funzionano i template di Wordpress
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Kürzlich hochgeladen (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Use Symfony2 components inside WordPress

  • 1. Use Symfony2 components inside WordPress (…and live happily)
  • 2. Walter Dal Mut  Cofounder at Corley S.r.l.  First level degree Electronic Engineering  Ungraduated student of Computer Science Maurizio Pelizzone  Cofounfer at Mavida S.n.c  WordPress Lover
  • 3.
  • 4.
  • 5. Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP components that solve common web development problems Fabien Potencier http://fabien.potencier.org/article/49/what-is-symfony2
  • 6. Use Composer autoload in your theme
  • 8. Monolog is a logging library for PHP 5.3 used by Symfony2. It is inspired by the Python LogBook library.
  • 9. Get Monolog Website: https://github.com/Seldaek/monolog Using Monolog: Create a new composer.json file { "require": { "monolog/monolog": "1.1.*" } } curl -s http://getcomposer.org/installer | php php composer.phar install
  • 11.
  • 12. … and use in your theme
  • 13.
  • 14.
  • 16. Assetic is an asset management framework for PHP. Assetic is based on the Python webassets library
  • 17. Get Assetic Website: https://github.com/kriswallsmith/assetic Using Assetic: Create a new composer.json file { "require": { "kriswallsmith/assetic": "v1.0.4" } } curl -s http://getcomposer.org/installer | php php composer.phar install
  • 18. GOAL: Merge, Minimize and Compile all javascript loaded through WordPress
  • 19.
  • 20.
  • 21.
  • 24. Twig: the flexible, fast, and secure template engine for PHP. Twig uses a syntax similar to the Django and Jinja template languages which inspired the Twig runtime environment.
  • 25. Why using a Template Engine ?
  • 26. PHP doesn't support many features modern template languages should have nowadays o Concision o Template oriented Syntax o Reusability o "Security" by default  I'll explain in the next slides  Read more on dedicated webpages. Read more at: http://fabien.potencier.org/article/34/templating-engines-in-php
  • 27. Concision PHP TWIG <?php echo $name ?> {{name}} <?php echo {{name|escape}} htmlspecialchars( $name, ENT_QUOTES, No short version it's 'UTF-8') already the short ?> Short tags version. <?=$name?> Using short tags could creates problems. You have to enable the short tags that are disabled by default.
  • 28. Template oriented Syntax PHP TWIG <?php if ($items): ?> {% for item in items %} <?php foreach ($items as $item): ?> * {{ item }} * <?php echo $item ?> {% else %} <?php endforeach; ?> No item has been found. <?php else: ?> {% endfor %} No item has been found. <?php endif; ?> It's more clear and use a new syntax.
  • 29. Reusability <!-- base.html --> <!-- index.html --> <html {% extends "base.html" %} xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> {% block head %} <head> {{ block.super }} {% block head %} <link rel="stylesheet" href="main.css" /> <link rel="stylesheet" href="main.css" /> {% endblock %} {% endblock %} </head> {% block content %} <body> Index content {% block content %}{% endblock %} {% endblock %} </body> </html>
  • 30. Security " I'm not saying PHP is not a secure language, far from it. But needless to say that escaping a variable in a template is just a nightmare. " Sometimes, security should be enabled by default, especially for templates written by non-developers who are not necessarily aware of the common web threats like XSS or CSRF. @fabpot PHP TWIG Output is escaped by default. <?php echo htmlspecialchars( {% autoescape off %} $var, {{ object.as_html }} ENT_QUOTES, {% endautoescape %} 'UTF-8') ?> I'm well aware of the automatic output escaping problems.
  • 31. Get Twig Website: http://twig.sensiolabs.org Twig C Extensions: https://github.com/derickr/twig-ext.git Using composer: Create a new composer.json file { "require": { "twig/twig": "1.*" } } curl -s http://getcomposer.org/installer | php php composer.phar install
  • 32. Twig & WordPress Using Twig into a wordpress plugin/theme could simplify and improve the development. • Plugin development (views) • Theme development
  • 33. Integrating Twig into a Plugin Just initialize Twig and use it. Using a static reference to share the Twig instance (simple way). function get_twig() { static $twig; if (!$twig) { $loader = new Twig_Loader_Filesystem(__DIR__ . '/templates'); $twig = new Twig_Environment($loader, array('cache' => false)); } return $twig; }
  • 34. Render a template During the Twig initialization we specify the view location ("templates" folder). Now you can create a Twig view and save it. Into your plugin just link to it: $template = get_twig()->loadTemplate('tweets.twig'); echo $template->render(array('elements' => $unpack)); In this example we load the "tweets.twig" view and pass the elements variable.
  • 35. WP Plugin Example You can checkout an example at: • https://github.com/wdalmut/wp-simple-tweets In this example we add a widget into the admin dashboard that shows tweets of @CorleyCloud account.
  • 36. Make a template using Twig WordPress is designed to use PHP as template engine. We can force to integrate Twig as the default templating system. You can find an example of integration at: https://github.com/wdalmut/wp-twig-theme This example realize a simple blank template with some WP functionalities (sidebars, posts, pages, archives).
  • 37. Making a Twig Proxy WordPress uses a lot of functions to generate pieces of html. To speedup the Twig integration we can create a simple proxy that enable WP functions into a Twig template. class TwigProxy { public function __call($function, $arguments) { if (!function_exists($function)) { throw new Exception("{$function} not exists."); return NULL; } return call_user_func_array($function, $arguments); } }
  • 38. Using the Twig Proxy This proxy allows us to call WordPress functions into a view. <div id="sidebar"> {% if not wp.dynamic_sidebar("Sidebar Widgets") %} {{ wp.get_search_form }} <!-- continue --> </div> "dynamic_sidebar" and "get_search_form" are WP functions.
  • 39. Load Twig templates instead PHPs We can use WordPress hooking system to override the default template loading. • add_filter o home_template o single_template o page_template o 404_template o archive_template o Etc, etc... • add_action o template_include  Engage Twig and prepare data to view.
  • 40. Layout management Instead of use get_header and get_footer that break HTML we can use template inheritance of Twig. {% extends "base.twig" %} {% block title %} {{ parent() }} | Page Not Found {% endblock %} {% block content %} <h2>Error 404 - Page Not Found</h2> {% endblock %}
  • 41. Enjoy with Twig Twig is extremely simple and powerful, you can play and enjoy with this great template engine and get more power during your wp development. Have a nice day
  • 42. ?
  • 43. Thank you! Walter Dal Mut walter.dalmut@gmail.com @wdalmut Maurizio Pelizzone maurizio@mavida.com @miziomon