Skip to content

Instantly share code, notes, and snippets.

@joelpittet
Forked from markhalliwell/classes.twig
Created July 3, 2014 05:31
Show Gist options
  • Save joelpittet/3eea67f65b80a3f25ae4 to your computer and use it in GitHub Desktop.
Save joelpittet/3eea67f65b80a3f25ae4 to your computer and use it in GitHub Desktop.
{% attributes.class.add([
'node',
'node--type-' ~ node.bundle|class,
node.promoted ? 'node--promoted',
node.sticky ? 'node--sticky',
not node.published ? 'node--unpublished',
preview ? 'node--preview',
'node--view-mode-' ~ view_mode|class
]).remove([
'some-module-class'
]) %}
<article {{attributes}}>
vs.
{% set classes = [
'node',
'node--type-' ~ node.bundle|class,
node.promoted ? 'node--promoted',
node.sticky ? 'node--sticky',
not node.published ? 'node--unpublished',
preview ? 'node--preview',
'node--view-mode-' ~ view_mode|class
]
%}
<article class="{{ attributes.class.add(classes).remove(['some-module-class']) }}"{{ attributes|without('class') }}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment