Skip to content

Instantly share code, notes, and snippets.

@yanniboi
Created November 21, 2013 16:10
Show Gist options
  • Save yanniboi/7584548 to your computer and use it in GitHub Desktop.
Save yanniboi/7584548 to your computer and use it in GitHub Desktop.
Writing a theme function and TWIG template for Instagram Block (drupal 8)
{#
/**
* @file
* Default theme implementation of an Instagram image link.
*
* Available variables:
* - data: The entire data array returned from the Instagram API request.
* - href: The url to the Instagram post page.
* - src: The source url to the instagram image.
* - width: The display width of the image.
* - height: The display height of the image.
*
* @ingroup themeable
*/
#}
{% spaceless %}
<a class="group" target="_blank" rel="group1" href="{{ href }}">
<img height="{{ height }}px" width="{{ width }}px" src="{{ src }}">
</a>
{% endspaceless %}
/**
* Implements hook_theme().
*/
function instagram_block_theme() {
return array(
'instagram_block_image' => array(
'variables' => array('height' => NULL,'width' => NULL, 'src' => NULL, 'href' => NULL),
'template' => 'instagram-block-image',
),
);
}
$content['children'][$post->id] = array(
'#markup' => '',
'#theme' => 'instagram_block_image',
'#data' => $post,
'#href' => $post->link,
'#src' => $post->images->thumbnail->url,
'#width' => $configuration['width'],
'#height' => $configuration['height'],
'#attached' => array(
'css' => array(
drupal_get_path('module', 'instagram_block') . '/css/block.css',
),
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment