Enhance your WordPress development with Twig and Clarkson - WordCamp Nederland 2016

Jaime Martínez
Jaime MartínezDeveloper at Level Level
ENHANCEyour
WordPress development
With TWIG and CLARKSON
Jaime Martínez
Enhance your WordPress development with Twig and Clarkson - WordCamp Nederland 2016
Do you know
TWIG?
TWIG?
TWIG?
Have you worked with
TWIG?
So what is
TWIG?
TWIG?Twig is a modern template engine for PHP.
TWIG?
So what is
CLARKSON?
Clarkson is a WordPress plugin which
encourages writing object-oriented code.
Clarkson is a WordPress plugin which
encourages writing object-oriented code.
Clarkson is a WordPress plugin which
encourages writing object-oriented code.
Enhance your WordPress development with Twig and Clarkson - WordCamp Nederland 2016
What PROBLEM
Are we trying to SOLVE?
Enhance your WordPress development with Twig and Clarkson - WordCamp Nederland 2016
Better (modern) templating
Separation of Concern
Presentation
-
View
Logic
-
Controller
Data access
-
Model
Presentation
-
View
Logic
-
Controller
Data access
-
Model
How do I magically register variables?
How do I magically register variables?
Menu item a Menu item b
©WCNL Just some footer text - 2015
<footer class="content-info">

<?php if ( has_nav_menu( 'footer-menu' ) ) { ?>

<nav class="footer-nav">

<?php wp_nav_menu(['theme_location' => 'footer-menu']); ?>

</nav>

<?php } ?>


<?php echo get_option('ll-footer-text') .' - Copyright ' .
date('Y');?>

</footer>
get_template_part(‘footer’)
<footer class="content-info">

{% if ( footer.menu is empty ) %}

<nav class="footer-nav">

{{ footer.menu }}

</nav>

{% endif %}



{{ footer.text | raw }}


</footer>
footer.twig
class Footer {
function __construct() {

add_filter( 'clarkson_context_args', array( $this, 'add_context_args' ) );

}

function get_text(){

return get_option('ll-footer-text') .' - Copyright ' . date('Y');

}

function add_context_args( $objects ) {

$objects['footer']['menu'] = wp_nav_menu(['theme_location'=>'footer-menu']);

$objects['footer']['text'] = $this->get_text();

return $objects;

}


}
footer.php
How do I set up my
TEMPLATES?
Enhance your WordPress development with Twig and Clarkson - WordCamp Nederland 2016
single.php > single.twig
{% include 'defaults/head.twig' %}
<main class="main">

{% block content %}

{% include 'partials/content.twig' %}

{% endblock %}

</main>
<sidebar>
{% block sidebar %}

{% include 'partials/sidebar.twig' %}

{% endblock %}
</sidebar>
{% include 'defaults/footer.twig' %}
Set up a layout file (layouts/2-columns.twig)
{% extend 'layouts/2-columns.twig' %}



{% block content %}


{% include 'post/content.twig' %}
{# Or some other custom HTML #}

{% endblock %}
Extend this layout file [single.twig]
Autotaalglas live! Jaime’s talk on WCNL 2016
Prefix - Level Level
WCNL JAIME
This is a link and this is regular text
Autotaalglas live! Jaime’s talk on WCNL 2016
Prefix - Level Level
WCNL JAIME
This is a link and this is regular text
<div class="grid-cell">
{% block content %}
Default fallback content

{% endblock %}
</div>
Global partial file [partials/teaser.twig]
{% extend 'partials/teaser.twig' %}
{% block content %}
<script type="text/javascript">

// Some Javascript to load Advertisement

</script>
{% endblock %}
Extend this partial [internal-ad/teaser.twig]
How did MODULAR
CSS help us?
SMACCS / OOCSS / BEM / AtomCSS
Autotaalglas live! Jaime’s talk on WCNL 2016
Prefix - Level Level
WCNL JAIME
This is a link and this is regular text
Autotaalglas live! Jaime’s talk on WCNL 2016
Prefix - Level Level
WCNL
This is a link
Autotaalglas live! Jaime’s talk on WCNL 2016
Prefix - Level Level
WCNL
This is a link
grid-cell
1x2
grid-cell
1x1
grid-cell
1x1
grid-cell
2x1
Prefix - Level Level
WCNL JAIME
This is a link and this is regular text
Jaime’s talk on WCNL 2016 Autotaalglas live!
Prefix - Level Level
WCNL
This is a link
Jaime’s talk on WCNL 2016 Autotaalglas live!
Prefix - Level Level
WCNL
This is a link
Jaime’s talk on WCNL 2016 Autotaalglas live!
grid-cell
1x2
grid-cell
1x1
grid-cell
1x1
grid-cell
2x1
<div class="grid-cell grid-cell-1x2 grid-cell-post">

<div class="grid-cell grid-cell-2x1 grid-cell-post">

<div class="grid-cell grid-cell-1x2 grid-cell-partner-post">
<div class="grid-cell grid-cell-1x1 grid-cell-internal-ad">

<div class="grid-cell grid-cell-1x1 grid-cell-post">

<div class="grid-cell grid-cell-1x1 grid-cell-post">
<div class="grid-cell grid-cell-1x2 grid-cell-partner-post">
<div class="grid-cell grid-cell-2x1 grid-cell-internal-ad">
How to work with
CUSTOM POST TYPES
Autotaalglas live! Jaime’s talk on WCNL 2016
Prefix - Level Level
WCNL JAIME
This is a link and this is regular text
Autotaalglas live! Jaime’s talk on WCNL 2016
Prefix - Level Level
WCNL
This is a link
Autotaalglas live! Jaime’s talk on WCNL 2016
Prefix - Level Level
WCNL
This is a link
POST
POST
PARTNER
POST
AD
POST
CLARKSON
POST
POST
PARTNER
AD
class post extends Clarkson_Post {


public function get_grid_size(){


return get_post_meta( $this->get_id(), 'll-grid-size');


}

}
themes/wcnl2016/wordpress-objects/post.php
class ll_partner_post extends post {

public function get_title() {



$title = parent::get_title();

$title ="Prefix - " . $title;



return $title;
}
}
themes/wcnl2016/wordpress-objects/ll-partner-post.php
How do I get my
POST DATA?
<?php
$post = new Post( $post );
echo $post->get_grid_size();
PHP
<div class="grid-cell grid-cell-{{ object.get_grid_size() }}">


<a href="{{ object.get_permalink() }}">

{{ object.get_title() | upper }}

</a>

</div>
Twig
SO:

SO:

Twig templates (include, extend, embed, overwrite blocks)
SO:

Twig templates (include, extend, embed, overwrite blocks)
Magically register variables
SO:

Twig templates (include, extend, embed, overwrite blocks)
Magically register variables
Encourage separation of concern & modularity
SO:

Twig templates (include, extend, embed, overwrite blocks)
Magically register variables
Encourage separation of concern & modularity
OO WordPress Objects
ADIOS!

Visit wp—clarkson.com/core by Level Level.
Jaime Martínez
@jmslbam
level-level.com
1 of 56

Recommended

WordCamp NL 2016 by
WordCamp NL 2016WordCamp NL 2016
WordCamp NL 2016Theo van der Zee
948 views69 slides
Enhance your WordPress development with Twig through Clarkson - WordCamp Barc... by
Enhance your WordPress development with Twig through Clarkson - WordCamp Barc...Enhance your WordPress development with Twig through Clarkson - WordCamp Barc...
Enhance your WordPress development with Twig through Clarkson - WordCamp Barc...Jaime Martínez
398 views47 slides
ChatGPT and the Future of Work - Clark Boyd by
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
24.3K views69 slides
Getting into the tech field. what next by
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
5.7K views22 slides
Google's Just Not That Into You: Understanding Core Updates & Search Intent by
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
6.4K views99 slides
How to have difficult conversations by
How to have difficult conversations How to have difficult conversations
How to have difficult conversations Rajiv Jayarajah, MAppComm, ACC
5K views19 slides

More Related Content

Recently uploaded

Mini-Track: Challenges to Network Automation Adoption by
Mini-Track: Challenges to Network Automation AdoptionMini-Track: Challenges to Network Automation Adoption
Mini-Track: Challenges to Network Automation AdoptionNetwork Automation Forum
17 views27 slides
Case Study Copenhagen Energy and Business Central.pdf by
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdfAitana
17 views3 slides
Network Source of Truth and Infrastructure as Code revisited by
Network Source of Truth and Infrastructure as Code revisitedNetwork Source of Truth and Infrastructure as Code revisited
Network Source of Truth and Infrastructure as Code revisitedNetwork Automation Forum
32 views45 slides
GDSC CTU First Meeting Party by
GDSC CTU First Meeting PartyGDSC CTU First Meeting Party
GDSC CTU First Meeting PartyNational Yang Ming Chiao Tung University
11 views25 slides
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
115 views25 slides
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...James Anderson
126 views32 slides

Recently uploaded(20)

Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana17 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson126 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely29 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman38 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays24 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2218 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc72 views
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... by The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn26 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...

Featured

The six step guide to practical project management by
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
36.6K views27 slides
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright... by
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
12.7K views21 slides
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present... by
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
55.5K views138 slides
12 Ways to Increase Your Influence at Work by
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
401.7K views64 slides
ChatGPT webinar slides by
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slidesAlireza Esmikhani
30.4K views36 slides

Featured(20)

The six step guide to practical project management by MindGenius
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius36.6K views
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright... by RachelPearson36
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson3612.7K views
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present... by Applitools
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools55.5K views
12 Ways to Increase Your Influence at Work by GetSmarter
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter401.7K views
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G... by DevGAMM Conference
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference3.6K views
Barbie - Brand Strategy Presentation by Erica Santiago
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago25.1K views
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well by Saba Software
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software25.2K views
Introduction to C Programming Language by Simplilearn
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn8.4K views
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr... by Palo Alto Software
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
Palo Alto Software88.4K views
9 Tips for a Work-free Vacation by Weekdone.com
9 Tips for a Work-free Vacation9 Tips for a Work-free Vacation
9 Tips for a Work-free Vacation
Weekdone.com7.2K views
How to Map Your Future by SlideShop.com
How to Map Your FutureHow to Map Your Future
How to Map Your Future
SlideShop.com275.1K views
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -... by AccuraCast
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...
AccuraCast3.4K views
Exploring ChatGPT for Effective Teaching and Learning.pptx by Stan Skrabut, Ed.D.
Exploring ChatGPT for Effective Teaching and Learning.pptxExploring ChatGPT for Effective Teaching and Learning.pptx
Exploring ChatGPT for Effective Teaching and Learning.pptx
Stan Skrabut, Ed.D.57.7K views
How to train your robot (with Deep Reinforcement Learning) by Lucas García, PhD
How to train your robot (with Deep Reinforcement Learning)How to train your robot (with Deep Reinforcement Learning)
How to train your robot (with Deep Reinforcement Learning)
Lucas García, PhD42.5K views
4 Strategies to Renew Your Career Passion by Daniel Goleman
4 Strategies to Renew Your Career Passion4 Strategies to Renew Your Career Passion
4 Strategies to Renew Your Career Passion
Daniel Goleman122K views
The Student's Guide to LinkedIn by LinkedIn
The Student's Guide to LinkedInThe Student's Guide to LinkedIn
The Student's Guide to LinkedIn
LinkedIn88K views

Enhance your WordPress development with Twig and Clarkson - WordCamp Nederland 2016