Skip to content

Instantly share code, notes, and snippets.

View renebakx's full-sized avatar

René Bakx renebakx

View GitHub Profile
@renebakx
renebakx / tagmanager.php
Created December 16, 2020 09:14
Writing the iframe tag at the top of your html.html.twig file in Drupal 8/9
<?php
function tagmanager_page_top(array &$page_top) {
if (FALSE === \Drupal::service('router.admin_context')->isAdminRoute()) {
$page_top['above'] = [
'#noscript' => true,
'#type' => 'html_tag',
'#tag' => 'iframe',
'#attributes' => [
'src' => sprintf('https://www.googletagmanager.com/ns.html?id=%s',$settings->get('gtm_code')),
'height' => 0,
@renebakx
renebakx / drupal8_8.theme.php
Created January 21, 2020 15:21
Re-add views theme suggestions for Drupal 8.8
/**
* Since the patches/fixes for issues
* 2923634 - [PP-1] Use hook_theme_suggestions in views
* 2118743 - [PP-3] Twig debug output does not display all suggestions when an array of theme hooks is passed to #theme
*
* Won't most likely not be in core before D9 lands and frontend developers still rely on those hints being available
* in the twig debug.
*
* You can add this snippet to add them back.
* But be carefull, this version doesn't merge or keep the $suggestions other modules or theme might have added!
@renebakx
renebakx / prerender
Created August 29, 2014 15:26
init.d script fo running prerender.io as a service with logging (redhat/centos)
#!/bin/sh
#
# chkconfig: 35 99 99
# description: prerender.js server for the given user
#
. /etc/rc.d/init.d/functions
APPNAME="Prerender"
@renebakx
renebakx / field.tpl.twig
Created September 7, 2017 12:07
Rendering a single field with multiple items at random in Drupal 8 TWIG
{#
So you have field that can hold 5 images, but you want them to render at random in the frontend?
No problem, get https://www.drupal.org/project/tlh version 8.x-1.6 or higher and use the shuffle filter!
#}
{% for item in items|shuffle %}
{{- item.content -}}
{% endfor %}
{# Be aware of render cache when doing this trick #}
# Doesn't show fields to translate
tndt_config.siteconfig:
type: config_object
label: 'Sitewide Configuration'
mapping:
right_text:
type: string
label: 'Text block right'
translatable: true
@renebakx
renebakx / tndt_config.schema.yml
Last active May 8, 2019 06:42
tndt_config.schema.yml
tndt_config.siteconfig:
type: config_object
mapping:
right_text:
type: string
label: 'Text block right'
translatable: true
right_title:
type: string
label: 'Title block right'
@renebakx
renebakx / settings.md
Last active January 23, 2018 09:22
No more drush cr for Drupal 8 theme development

this bit goes in development.services.yml

services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory
parameters:
  twig.config:
    debug: true
    auto_reload: null
 cache: false
@renebakx
renebakx / uuids.php
Created April 30, 2017 18:06
Laravel 5.4 UUID Trait
<?php
namespace App\Traits;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Ramsey\Uuid\Uuid;
trait Uuids {
@renebakx
renebakx / keybase.md
Created October 11, 2017 08:24
keybase.md

Keybase proof

I hereby claim:

  • I am renebakx on github.
  • I am renebakx (https://keybase.io/renebakx) on keybase.
  • I have a public key ASCmtcme0jjfGgvE66XnuKP7-t0RedQHrzV6D4WTTDzuowo

To claim this, I am signing this object:

@renebakx
renebakx / .bash_profile
Last active September 29, 2017 10:17
switching between project Drush and Drupal, and the global installed
# These two functions asume your are in de public folder of a D8 project
# Run drupal from project when possible
function dpl() {
if [ -f "../vendor/bin/drupal" ]
then
../vendor/bin/drupal "$@";
else
drupal "$@";
fi