Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Test Drive Twig with Sculpin
Search
Oliver Davies
July 25, 2015
Programming
1
650
Test Drive Twig with Sculpin
Oliver Davies
July 25, 2015
Tweet
Share
More Decks by Oliver Davies
See All by Oliver Davies
Building Static Websites with Sculpin
opdavies
0
1.5k
Taking Flight with Tailwind CSS
opdavies
0
4.8k
TDD - Test Driven Drupal
opdavies
0
3.6k
Building "Build Configs"
opdavies
0
370
Communities and contribution
opdavies
0
150
Working without Workspace
opdavies
0
210
Things you should know about PHP
opdavies
1
700
An Introduction to Mob Programming
opdavies
0
230
Deploying PHP applications with Ansible, Ansible Vault and Ansistrano
opdavies
0
6.1k
Other Decks in Programming
See All in Programming
距離関数を極める! / SESSIONS 2024
gam0022
0
280
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
130
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
CSC509 Lecture 13
javiergs
PRO
0
110
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
What's new in Ruby 2.0
geeforr
343
31k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Docker and Python
trallard
40
3.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Designing for humans not robots
tammielis
250
25k
Side Projects
sachag
452
42k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Designing Experiences People Love
moore
138
23k
Speed Design
sergeychernyshev
25
620
Six Lessons from altMBA
skipperchong
27
3.5k
Transcript
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