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
/**
* Implements hook_preprocess_menu().
*/
function vanilla_preprocess_menu(&$vars, $hook) {
if ($hook == 'menu_main') {
kint($hook);
$items = $vars['items'];
foreach ($items as $key => $item) {
$original_title = $vars['items'][$key]['title'];
$vars['items'][$key]['title'] = array(
@mortendk
mortendk / menu-main.html.twig
Last active November 3, 2022 10:32
svg inside a link in drupal menus
{% import _self as menus %}
{#
We call a macro which calls itself to render the full tree.
@see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ menus.menu_links(items, attributes, 0) }}
{% macro menu_links(items, attributes, menu_level) %}
{% import _self as menus %}
@mortendk
mortendk / snippets.cson
Created October 30, 2015 17:05
atom snippets for drupal twig
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
@mortendk
mortendk / classy-css.html
Created October 25, 2015 23:18
classy css selectors
Document all css class selectors that are in the classy theme.
<code>
.foo { }
.foo-bar { }
</code>
where it is filename.html.twig / filename.css
<h3>Available css selectors in the Classy theme:</h3>
@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.

@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 / 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 / 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 / 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']
},
$path = \Drupal::request()->getPathInfo();
if($path){
$foo = explode("/", $path);
$body_classes[] = 'path-' . $foo[1];
}