Created
November 21, 2013 16:10
-
-
Save yanniboi/7584548 to your computer and use it in GitHub Desktop.
Writing a theme function and TWIG template for Instagram Block (drupal 8)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
/** | |
* @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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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', | |
), | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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