Skip to content

Instantly share code, notes, and snippets.

View robdecker's full-sized avatar

Rob Decker robdecker

View GitHub Profile
@robdecker
robdecker / loop.twig
Created October 31, 2019 17:24
[Print items/blocks in region.html.twig] #d8 #twig
{# Loop through items #}
{% for key, child in elements if key|first != '#' %}
<div class="{{ loop.first ? 'class-1' : 'class-2' }}">{{ child }}</div>
{% endfor %}
@robdecker
robdecker / 1.md
Last active February 22, 2022 14:17
[Composer commands] #composer #d8
@robdecker
robdecker / snippet.php
Created October 18, 2019 19:12
[Get translated node/entity] #d8
if ($entity->hasTranslation('en')) {
$translated_entity = $entity->getTranslation('en');
$translated_title = $translated_entity->getTitle();
}
@robdecker
robdecker / snippet.php
Last active October 18, 2019 19:09
[Get current language] #d8
// 2 digit code
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
// Name
$language = \Drupal::languageManager()->getCurrentLanguage()->getName();
@robdecker
robdecker / Breadcrumbs.php
Last active October 17, 2019 19:49 — forked from jonpugh/Breadcrumbs.php
[Add Taxonomy Term to a Node's Breadcrumb in Drupal 8] #d8
<?php
// src/Breadcrumbs.php
namespace Drupal\modulename;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Link;
$bundle_label = \Drupal::entityTypeManager()
->getStorage('node_type')
->load($node->bundle())
->label();
@robdecker
robdecker / snippet.twig
Last active October 18, 2019 19:13
[Get all variables in twig template] #d8 #twig
<pre>{{ dump() }}</pre>
{{ dump(_context|keys) }}
<ol>
{% for key, value in _context %}
<li>{{ key }}</li>
{% endfor %}
</ol>
@robdecker
robdecker / how-to-get-youtube-video-id.md
Last active March 30, 2021 22:14 — forked from jakebellacera/how-to-get-youtube-video-id.md
[Learn how to get the ID of any YouTube video] #video #youtube

How to get the ID of any YouTube Video

This article walks you through how to get the ID of any YouTube video.

How to get a YouTube video ID from a youtube.com page URL

You may be watching the video or just happened to visit a link to a video. The video ID will be located in the URL of the video page, right after the v= URL parameter.

@robdecker
robdecker / .scss
Last active November 2, 2019 01:41
[Bootstrap grid, using Susy & include-media] #bootstrap #sass
@import "susy";
@import "include-media";
$susy-columns: 12;
$susy-gutter-width: 15px;
$susy: (
columns: $susy-columns,
gutter-position: inside-static, // fixed-width width gutters
column-width: 120px,