Skip to content

Instantly share code, notes, and snippets.

View steveoliver's full-sized avatar

Steve Oliver steveoliver

View GitHub Profile
@steveoliver
steveoliver / gist:5879504
Created June 27, 2013 19:18
Discussion between steveoliver and Fabianx on the topic of Twig variable drillability.
***: Buffer Playback...
Fabianx: [15:17:27] steveoliver: pong
Fabianx: [15:17:50] steveoliver: Can you pass me the link to drill able again (sorry during moving, not much time left  )
***: Playback Complete.
steveoliver: 2008450
Druplicon: https://drupal.org/node/2008450 => Provide for a drillable variable structure in Twig templates [#2008450] => Drupal core, theme system, major, needs work, 12 comments, 10 IRC mentions
steveoliver: Fabianx: ^^
Fabianx: steveoliver: So implementation is:
Fabianx: ( proof-of-concept)
Fabianx: * Add a new parameter to render and theme.
Discussing this on our call today, Fabianx pointed out one possibility. Take our example of image field instances within a node template:
To get at the src (or any other) attribute of the first image field instance, one would print:
<code>{{ content.field_image.attributes.src }}</code>
1. The field <code>attributes</code> have not yet been prepared in the context of the parent node template.
2. <code>TwigTemplate::getAttribute()</code> determines the attribute does not exist and then calls a function, tentatively named <code>render_structure()</code>, which returns the variables as would be available in the child template.
3. Then .src and other variables are available.
@steveoliver
steveoliver / gist:4750736
Created February 10, 2013 19:31
Drupal 8 Best Practices in Preprocess functions and Twig templates
<h3 id="bestpractices">Best Practices in Preprocess Functions and Twig Templates</h3>
In order to minimize wasteful calls to unneeded resources and make Drupal 8 themeing as performant as possible, please follow these best practices:
<ol>
<li>Always call <code>t()</code> within templates; never call t() in preprocess.</li>
<li>Always return render arrays instead of ever calling <code>theme()</code> within a preprocess function.</li>
</ol>
@steveoliver
steveoliver / Partial response handling notes
Created January 31, 2013 20:27
Notes on sdboyers comments about partial response handling
// controller arguments
$arguments = $this->resolver->getArguments($request, $controller);
// call controller
// i.e. from menu_execute_active_handler
//
$response = call_user_func_array($controller, $arguments);
// if controller wasn't smart enough to return a complete response...
@steveoliver
steveoliver / gist:4081603
Created November 15, 2012 21:59
Drupal 8 Twig Debug Comments
<!-- BEGIN 'comment_wrapper__node_article' THEME MARKUP -->
<!-- FROM core/themes/stark/templates/node/node--1.html.twig -->
<!-- FILE NAME SUGGESTIONS:
x node--1.html.twig
* node--article.html.twig
* node.html.twig
-->
<article id="node-1">
<h2>Title</h2>
// ...
@steveoliver
steveoliver / user-login-block-better.html.twig
Created November 7, 2012 19:21
User login block (better) extends User login block.
{# modules/user/templates/user-login-block.html.twig #}
{% block "login-link" %}
<div class="user-login-block-link">
{{ link }}
</div>
{% endblock %}