Skip to content

Instantly share code, notes, and snippets.

View renebakx's full-sized avatar

René Bakx renebakx

View GitHub Profile
@renebakx
renebakx / hideme.twig
Created February 16, 2017 10:10
twig trick to hide content without marking it as a comment {# #}
Sometimes you need to implement HTML from a style guide, but commenting out the whole block with {# #} makes it unreadable.
This little 'trick' let's your editor do proper syntax highlighting without showing the HTML in your output
{% if false == true %}
<div class="form-column">
<label for="upload">Your Resumé</label>
<div class="file-upload-field">
<div class="name-display">
<svg class="icon icon-check"><use xlink:href="#icon-check"></use></svg>
@renebakx
renebakx / cruftless.info.yml
Created October 20, 2016 14:59
cruftless Drupal 8 Theme
name: Cruftless
type: theme
description: Cruftless is Stable without libraries
package: BadIdeas
core: 8.x
base theme: false
regions:
header: Header
content: Content
footer: Footer
@renebakx
renebakx / macro_split.tpl.twig
Last active May 4, 2017 10:02
Split a string into two colors
{% macro split_title(text) %}
{% set text = render(text) %} {# only when doing twig for drupal 7 #}
{% set chunks = text|split('~') %}
{% for chunk in chunks %}
{{ (loop.index0 is odd)?"<em>"~chunk~"</em>":chunk}}
{% endfor %}
{% endmacro %}
<h3>{{ split_title('This is a ~text~ with some ~colors~') }}</h3>
@renebakx
renebakx / ajax_response.md
Last active February 18, 2016 09:35
A very basic Drupal 8 AJAX repsonse

router.yml :

simple_twitter.ajax_controller_get_tweets:
  path: '_simple_twitter/tweets/{name}/{number}'
  defaults:
    _controller: '\Drupal\simple_twitter\Controller\AjaxController::getTweetsForUserAction'
    _title: 'getTweetsForUser'
 requirements:
@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 / bash_profile
Created February 8, 2016 09:29
PHP 5 and 7 with MAMP
export PHP7=1; // on opening your terminal
// Goes in your ~/.bash_profile
if [ -z "$PHP7" ]; then
export DRUSH_PHP='/Applications/MAMP/bin/php/php7.0.0/bin/php'
export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php/php7.0.0/bin/:~/bin:$JAVA_HOME/bin:$PATH
else
export DRUSH_PHP='/Applications/MAMP/bin/php/php5.5.26/bin/php'
export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php/php5.5.26/bin/:~/bin:$JAVA_HOME/bin:$PATH
fi
@renebakx
renebakx / views-view-unformatted.tpl.twig
Created July 10, 2015 14:03
Splitting view rows in upcoming and recent on a date without creating a viewspluging
{% for index,rawdata in view.result %}
{% set row_date = rawdata.field_field_conference_date[0]['raw']['value'] %}
{% set upcoming = false %}
{% set recent = false %}
{% if date(row_date) > date() %}
{% if not upcoming %}
<small>{{ 'Upcoming'|t }}</small>
{% set upcoming = true %}
{% endif %}
{% else %}
@renebakx
renebakx / use set instead of macro
Created February 19, 2015 10:29
twig set block
{# If creating a responsive theme, you sometimes need to duplicate content in a template and a macro can be an option but sometimes the overhead is to much #}
{% set loginblock %}
<li><a href="{{ url('login') }}">Log in</a></li>
<li><a href="{{ url('signup') }}">Sign up</a></li>
{% endset %}
... more html...
<ul class="nav nav-secondary">
@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"
<?php
// build from drupal_get_query_parameters();
$filterQuery = array('news', 'blog', 'article');
// build query
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->propertyCondition('type', 'page');
$query->propertyCondition('status', 1);
$query->fieldCondition('field_page_type', 'value', $filterQuery, 'in');
$query->propertyOrderBy('title', 'ASC');