Skip to content

Instantly share code, notes, and snippets.

@steffenr
Last active October 14, 2021 05:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steffenr/5011792 to your computer and use it in GitHub Desktop.
Save steffenr/5011792 to your computer and use it in GitHub Desktop.
Sample used in our second blog post on theming with Twig in Drupal 8
{% for book_id, menu in book_menus %}
<nav id="book-block-menu-{{ book_id }}" class="book-block-menu">
{{ menu }}
</nav>
{% endfor %}
<?php foreach ($book_menus as $book_id => $menu): ?>
<div id="book-block-menu-<?php print $book_id; ?>" class="book-block-menu">
<?php print render($menu); ?>
</div>
<?php endforeach; ?>
<?php
echo check_plain($title);
?>
{{ title|escape }}
{{ title|e('js') }}
{# Hier steht ein einzeiliger Kommentar #}
{# Hier steht ein mehrzeiliger Kommentar
mit weiteren Informationen zur Funktionsweise des Templates.
#}
<?php
// Hier steht ein einzeiliger Kommentar.
/*
* Hier steht ein mehrzeiliger Kommentar
* mit weiteren Informationen zur Funktionsweise des Templates.
*/
?>
<figure class="{{ item.attributes.class }}"{{ item.attributes }}>
{% if style %}
{% include 'core/themes/stark/templates/image/image_style.html.twig' with {image: item.image } %}
{% else %}
{% include 'core/themes/stark/templates/theme.inc/image.html.twig' with {image: item.image } %}
{% endif %}
{% if item.caption %}
<figcaption>
{{ item.caption }}
</figcaption>
{% endif %}
</figure>
{{ name }} <small>{{ '(Machine name: @type)'|t({ '@type': type }) }}</small>
<div class="description">{{ description }}</div>
<div class="poll">
<div class="title"><?php print $title ?></div>
<?php print $results ?>
<div class="total">
<?php print t('Total votes: @votes', array('@votes' => $votes)); ?>
</div>
</div>
<div class="links"><?php print $links; ?></div>
<div class="custom-wrapper">
<label for="<?php print $widgets['filter-myfield']->id; ?>">
<?php print $widgets['filter-myfield']->label ?>
</label>
<?php print $widgets['filter-myfield']->widget ?>
</div>
<div class="custom-wrapper">
<label for="{{ widgets.filter-myfield.id }}">{{ widgets.filter-myfield.label }}</label>
{{ widgets.filter-myfield.widget }}
</div>
<div id="taxonomy-term-{{ term.tid }}"{{ attributes }}>
{% if not page %}
<h2>{{ term_name }}</h2>
{% endif %}
<div class="content">
{{ content }}
</div>
</div>
<div id="taxonomy-term-<?php print $term->tid; ?>">
<?php if (!$page): ?>
<h2><?php print $term_name; ?></h2>
<?php endif; ?>
<div class="content">
<?php print render($content); ?>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment