Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Test Drive Twig with Sculpin
Search
Oliver Davies
July 25, 2015
Programming
770
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Test Drive Twig with Sculpin
Oliver Davies
July 25, 2015
Transcript
49 slides
Test Drive Twig with Sculpin AKA Get Ready for Theming
in Drupal 8
• What is Sculpin, and why should I use it?
• How to install Sculpin • How to build a Sculpin site • How to do cool things with Twig This Talk
Oliver Davies (opdavies) • Drupaler since 2007 • Senior Developer
at Microserve • Drupal 7 and 8 core contributor • Contrib project maintainer • User group, sprint, conference organiser whoami
Oliver Davies (opdavies) • Sculpin hobbyist • Twig enthusiast •
Former Jekyll user whoami
Sculpin
• Static site generator • Open source • Written in
PHP, based on Symfony components • CLI tool, based on Symfony Console • Markdown/HTML/Twig > HTML • Awesome for small sites, HTML prototypes and learning Twig. What is Sculpin?
Why use a static site generator at all? • Reduces
duplication / D.R.Y. • Better performance compared to dynamic sites • Faster to develop (maybe?) Why?
Drupal 8’s little brother • Both use YAML and Twig
• Both have content types • Both have taxonomies • Both have “fieldable entities” Similarities
Getting Started Installation and Configuration
$ curl -O https://download.sculpin.io/sculpin.phar $ chmod +x sculpin.phar $ mv
sculpin.phar /usr/local/bin/sculpin https://sculpin.io/download/ Install
Alternatives • Download via Composer • Clone from GitHub •
Use Sculpin Blog Skeleton or Sculpin Minimal • Use the Ansible role Install
Basic Site Structure app/ config/ sculpin_kernel.yml sculpin_site.yml source/ _layouts/ default.html
index.md
Configure app/config/sculpin_site.yml title: Oliver Davies source/_layouts/default.html {{ site.title }}
Configure app/config/sculpin_site_prod.yml imports: - sculpin_site.yml url: http://www.oliverdavies.uk google_analytics_tracking_code: UA-XXXXXX-1
Configure source/_layouts/default.html {% if site.google_analytics_tracking_code %} ... {% endif %}
app/config/sculpin_kernel.yml sculpin_content_types: posts: permalink: blog/:slug_title/ talks: Content Types
app/config/sculpin_kernel.yml sculpin_content_types: posts: permalink: blog/:slug_title/ taxonomies: [ tags, categories ]
talks: Taxonomies
source/_posts/2015-07-24-drupalcamp-north.md --- title: DrupalCamp North tags: - drupalcamp - drupalcamp-north
Taxonomies
source/_layouts/post.html --- use: [ ‘tags’ ] --- {% for tag
in page.tags %} {{ tag }} {% endfor %} Taxonomies
app/config/sculpin_kernel.yml sculpin_theme: theme: opdavies/oliverdavies15 Themes (Experimental)
Adding custom functionality. They are a thing. Bundles
$ sculpin generate $ sculpin generate --server $ sculpin generate
--server --watch $ sculpin generate --env=prod Build
Adding Content
Simplest Source File source/index.md --- --- # Hello World
Simplest Source File output_dev/ index.html
--- layout: default title: About --- # Hello World YAML
Front Matter
--- layout: default title: About foo: bar --- # Hello
World YAML Front Matter
Twig
source/_layouts/default.html <body class=”{% block body_classes ‘’ %}”> {% block content
%}{% endblock %} </body> Layouts
source/about.html --- {% block body_classes ‘page--about’ %} {% block content
%} <p>Content</p> {% endblock %} Blocks
source/about.md --- {% block body_classes ‘page--about’ %} {% block content
%} Content {% endblock %} Blocks
source/_layouts/post.html {% extends ‘default’ %} {% block content %}{% endblock
%} Template Inheritance
source/_partials/talk-listing-item.html <li> {% if talk.link -%}<a href="{{ talk.link }}">{%- endif
-%} {{ talk.title }} {% if talk.link %}</a>{% endif %} </li> Partials
source/talks.html <ul> {% for talk in page.talks %} {% include(‘talk-listing-item’)
%} {% endfor %} </ul> Partials
source/_partials/head.html {% if page.meta.og %} {% include "og" with {
og: page.meta.og } %} {% endif %} Partials
Twig Tips & Tricks
Filters {{ foo|upper }} {{ bar|lower }} {{ page.excerpt|replace( {
‘h2’: ‘h3’ } ) }} Tips & Tricks
Rendering objects and arrays {{ site.drupalorg.url }} Tips & Tricks
Loops {% for meetup in site.meetups %} {% if loop.first
%} ... {% endif %} {% endfor %} Tips & Tricks
Conditional logic {% if site.foo == ‘bar’ %} ... {%
else %} ... {% endif %} Tips & Tricks
Conditional logic {% set date = ‘now’|date(‘Y’) %} {% for
talk in page.talks if talk.date >= now %} ... {% endfor %} Tips & Tricks
Shorthand blocks {% block body_classes %}page--blog page--blog__list {% endblock %}
{% block body_classes ‘page--blog page--blog__list’ %} Tips & Tricks
Block appending {% block sidebar %} {{ parent() }} {%
endblock %} Tips & Tricks
Whitespace {% if site.foo == ‘bar’ -%} ... {%- endif
%} Tips & Tricks
Spaceless {% spaceless %} ... {% endspaceless %} Tips &
Tricks
Raw output {% raw %} {% if site.foo == ‘bar’
%} ... {% endif %} {% endraw %} Tips & Tricks
Links Links
Useful Links • http://bit.ly/sculpin-twig-resources
Questions @opdavies
More Decks by Oliver Davies
See All by Oliver Davies
Building Static Websites with Sculpin
opdavies
0
1.8k
Taking Flight with Tailwind CSS
opdavies
0
5.6k
TDD - Test Driven Drupal
opdavies
0
4.4k
Building "Build Configs"
opdavies
0
670
Communities and contribution
opdavies
0
370
Working without Workspace
opdavies
0
430
Things you should know about PHP
opdavies
1
950
An Introduction to Mob Programming
opdavies
0
490
Deploying PHP applications with Ansible, Ansible Vault and Ansistrano
opdavies
0
6.7k
Other Decks in Programming
See All in Programming
JavaScriptはシングルバイナリの夢を見るか / Does JavaScript Dream of a Single Binary?
ssssota
0
420
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
110
Promiseの向こう側へコンテキストを届ける ― proposal-async-context
seriseri
0
220
Spec-driven Development with AI
simas
PRO
0
2.3k
Proxmox x Talos Linux x Terraform で実現するなんかいい感じの Kubernetes クラスタ / A Sleek Kubernetes Cluster Powered by Proxmox, Talos Linux, and Terraform
nnaka2992
0
320
例外からRich Errorsまで Kotlinエラーハンドリングの進化を読み解く
shiita0903
0
250
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
270
protojson における文字化けの扱い
kazuki1023
0
470
数行の変更でDockerビルドを最大91%高速化~GitLab CIの実行基盤を社内40リポジトリに展開するまで~
picopico
3
850
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
210
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
170
Going Full Circle with Virtual Graphs and Relational Databases
michaelsimons
1
120
Featured
See All Featured
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
990
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.2k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
450
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
1
320
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
400
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
410
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
760
Agile that works and the tools we love
rasmusluckow
331
22k
How STYLIGHT went responsive
nonsquared
100
6.4k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.3k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
350
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
61k