Skip to content

Instantly share code, notes, and snippets.

View mortendk's full-sized avatar
🤠
git commit -m "yolo"

mortendk mortendk

🤠
git commit -m "yolo"
View GitHub Profile
@mortendk
mortendk / field--image.html.twig
Created September 18, 2013 15:06
field image twig
{# title wtf is this called label btw #}
{% if not label_hidden %}
<h3 {{ title_attributes }}>{{ label }}:&nbsp;</h3>
{% endif %}
{% for delta, item in items %}
{% if loop.length > 1 %} {# no wrappers if theres only 1 item#}
<section class="images" {{ content_attributes }}> {# wanna do a print all attributes but no class #}
@mortendk
mortendk / menu--level.html.twig
Created April 12, 2014 15:26
drupal8 menu dummy idea
{# level one
menu--level.html.twog
#}
{% if menu_level = 1 %}
<nav class="menu menu-{{ menu-name}}">
{% endif %}
<ul class="level-{{ menu_level }}">
{% for item in items %}
@mortendk
mortendk / gruntfile.js
Created April 18, 2014 00:40
styleguide grunt kss
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
//clean
clean: {
styleguide: ['styleguide'],
css: ['css']
},
//copy
@mortendk
mortendk / theme.inc
Created April 22, 2014 19:41
merging attributes
$variables['attributes']['class'] = 'test-attribute-merge-1';
$variables['content_attributes']['class'] ='test-content_attributes-merge-2';
$variables['attributes']['role'] = 'attributes-role';
$variables['content_attributes']['role'] = 'content_attributes-role';
$variables['title_attributes']['role'] = 'title-attributes-role';
$variables['item_attributes']['0']['role'] = 'item-attributes-role';
//wtf why u not merge
$path = \Drupal::request()->getPathInfo();
if($path){
$foo = explode("/", $path);
$body_classes[] = 'path-' . $foo[1];
}
@mortendk
mortendk / Gruntfile.js
Created May 28, 2014 15:45
grunt file for styleguide etc
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
//clean folders
clean: {
styleguide: ['styleguide'],
css: ['css'],
// images:['images']
},
@mortendk
mortendk / gist:923a97fd553fa602cc35
Created August 4, 2015 19:20
force drupal to test on classy
function testMessages() {
// Enable the Classy theme.
\Drupal::service('theme_handler')->install(['classy']);
$this->config('system.theme')->set('default', 'classy')->save();
....
@mortendk
mortendk / menu--main.html.twig
Created August 5, 2015 22:21
menu with first, last & count classes in twig Drupal8 template
{#
/**
* @file
* Theme override to display a menu.
*
* Available variables:
* - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item.
* - below: The menu item child items.
@mortendk
mortendk / twig-loop-template.html.twig
Last active April 29, 2016 09:29
twig loop template
{# loop template #}
{% for item in items %}
{# assing foo, bar or baz to the var foo then print em out #}
{%
set var = [
cycle(["foo", "bar", "baz"], loop.index),
]
%}
{% if loop.first %}
{# first #} {{ var }}
@mortendk
mortendk / template-choser.md
Last active April 29, 2016 09:32
Drupal8 concept for selecting templates form the ui

template chooser

Drupal8 is pretty awesome, but its a problem that you cant choose fromt the ui which template to use. Sure you can overwrite whats there (node--article.html.twig) but that dont give the end user a chance to later change in the site & can end up in even more templates & clutter.

template suggestions

Make it easy to provide a template suggestion for entities, blocks, pages, nodes, fields, menues, username, everything that have a template you should be able to give a suggestion.

class selector

A prepopulated list of classes that can be selected for a template.

The modules userbase is sitebuilders & themes that wants to provide variations for a site, developers dont have to provide templates after a site is build, and can rely on the theme to provide all the variations.