Skip to content

Instantly share code, notes, and snippets.

View renebakx's full-sized avatar

René Bakx renebakx

View GitHub Profile
@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');
@renebakx
renebakx / mongo.sh
Created November 20, 2011 11:24
starting mongo on OSX
#!/bin/bash
#MongoDB startup script with status and proper lockfile removing
#Version 1.0.1 20-nov-2011 Rene Bakx (rene@71media.net)
#Created on OS-X 10.7 but should work on other versions
if [ -z $1 ] ; then
echo "Usage: $0 [start|stop|restart|status] "
exit 1