node template background image url

See this issue http://drupal.stackexchange.com/questions/137319/getting-the-image-url-f...

...two methods are described and both work.

You can do this in twig:

See: https://www.drupal.org/node/1696760 regarding twig functions and filters.

=====================

Second you can do this in preprocess e.g.:

Clippy

Tiny gap under video HTML 5

It's because they are inline elements with resizable height (most inline elements are not explicitly resizable). If you set them to display: block; the gap goes away. You can also set vertical-align: top; to achieve the same result.

D8 How do I add a node ID as class to the <body> tag?

3
down vote
accepted
In mytheme.theme file: add the below code.

function mytheme_preprocess_html(&$variables) {
// Add node id to the body class.
$node = \Drupal::routeMatch()->getParameter('node');
if($node) {
$variables['attributes']['class'][] = 'node-' . $node->id();
}
}
This will add "node-{{nid}}" class in body tag.

The Simplest Way To Center Elements Vertically And Horizontally

The HTML

The idea, of course, revolves around flexbox. First, we create a container in which we want everything to be centered:

You can place this container div anywhere you want. In the live example above we've made it take up the whole width and height of the page.
The CSS

As we said earlier, we will be using only three lines of code. Here they are:

.container{
display: flex;
justify-content: center;
align-items: center;
}

Theme suggestion for D8 blocks

/**
* Implements hook_theme_suggestions_HOOK_alter() for form templates.
* @param array $suggestions
* @param array $variables
*/
function THEMENAME_theme_suggestions_block_alter(array &$suggestions, array $variables) {
// Block suggestions for custom block bundles.
if (isset($variables['elements']['content']['#block_content'])) {
array_splice($suggestions, 1, 0, 'block__bundle__' . $variables['elements']['content']['#block_content']->bundle());
}
}

Bind event listener to ajax loaded elements

$(document).on('click', '.dynamicelement', function() {
//DO SOMETHING;
});

$(.staticparent).on('click', '.dynamicelement', function() {
//DO SOMETHING;
});

Tweets for D8

https://api.twitter.com/1.1/statuses/user_timeline.json?count=10&screen_...

'media_url' => $tweet->entities->media[0]->media_url

Pages

Subscribe to Front page feed