Skip to content

Instantly share code, notes, and snippets.

View occupant's full-sized avatar

James occupant

  • University of British Columbia
  • Vancouver, BC
View GitHub Profile
@occupant
occupant / content_search.json
Created November 29, 2019 22:08
search content as json
[{"title":"Hi there","external_link":"http:\/\/www.frouamowi.com","link":"\/news\/november-11-2019\/hi-there","id":"957d8ee9-c4a2-4e4b-aae2-7e61d45c8a88","topic":"UBC Broadcasts","audience":"Okanagan Campus, Administrators"},{"title":"Antehabeo Defui Neo Torqueo","external_link":"http:\/\/www.tripororotacl.edu","link":"\/news\/november-11-2019\/antehabeo-defui-neo-torqueo","id":"3d7b82d2-aea1-44b4-bea3-ab4f5e002bed","topic":"Update","audience":"Staff, Vancouver Campus"},{"title":"Camur Conventio Pala","external_link":"http:\/\/www.duuicregesam.info","link":"\/news\/november-11-2019\/camur-conventio-pala","id":"df71c4a9-4de2-45c4-9af7-dc9d66b91318","topic":"UBC Broadcasts","audience":"Administrators"}]
[{"title":"Hi there","external_link":"http:\/\/www.frouamowi.com","link":"\/news\/november-11-2019\/hi-there","id":"957d8ee9-c4a2-4e4b-aae2-7e61d45c8a88","topic":"UBC Broadcasts","audience":"Okanagan Campus, Administrators","body":"Enim gemino modo scisco suscipit tum. Exerci mos nibh patria refoveo. Antehabeo eu euismod ex ideo interdico metuo secundum validus virtus. Bene comis consectetuer distineo euismod immitto lenis loquor uxor. Appellatio capto esca loquor odio pagus probo secundum voco wisi.","image":"\/sites\/default\/files\/feature-images\/2019-11\/generateImage_a2pJHP.jpeg"},{"title":"Antehabeo Defui Neo Torqueo","external_link":"http:\/\/www.tripororotacl.edu","link":"\/news\/november-11-2019\/antehabeo-defui-neo-torqueo","id":"3d7b82d2-aea1-44b4-bea3-ab4f5e002bed","topic":"Update","audience":"Staff, Vancouver Campus","body":"Bene haero secundum tation. Exerci facilisi facilisis feugiat gemino iriure iusto meus veniam. Abluo acsi brevitas dignissim fere minim paratus typicus verto volutpat.","ima
@occupant
occupant / Using field_view_field in page.tpl
Created October 21, 2016 16:48
Print a node field in a page.tpl.php
<?php
$background_image = field_view_field('node', $node, 'field_image_divider_background', array('label'=>'hidden','type' => 'image_url', ));
// type refers to the field formatter - image_url from the image_url_formatter madule in this case
// see - https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_view_field/7.x
?>
<?php if (!empty($background_image)): ?>
<div style="background-image:url(<?php print render($background_image); ?>)" class="imagebreak imagebreak--screened imagebreak--ctas non-clf" >
etc...
</div>
@occupant
occupant / THEMENAME.theme
Last active August 15, 2020 18:32
Add active class to active 'li' in Drupal 8 menus
function THEMENAME_preprocess_menu(&$variables, $hook) {
if ($hook == 'menu_main') {
THEMENAME_menu_active_item($variables['items']);
}
}
function THEMENAME_menu_active_item(&$items) {
$current_path = \Drupal::request()->getRequestUri();
foreach ($items as $key => $item) {
// if path is current path, set active to li
<?php
/**
* Theme_menu_tree doesn't provide any context information
* THIS SUCKS
* But you can use hook_block_view_alter to change the theme wrapper
* OUF!
*/
function MYTHEME_menu_tree(&$variables) {