Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jackrabbithanna/05dc85598e855609d63db905b090fa36 to your computer and use it in GitHub Desktop.

Select an option

Save jackrabbithanna/05dc85598e855609d63db905b090fa36 to your computer and use it in GitHub Desktop.
Theme CiviCRM Entity - example template, and preprocess
# civicrm-entity--civicrm-contact--full.html.twig
# place in your theme's "templates" directory
{#
/**
* @file
* Default template for a CiviCRM template.
*
* The following template suggestions are available:
* - civicrm-entity--ENTITY-TYPE.html.twig
* - civicrm-entity--ENTITY-TYPE--VIEW-MODE.html.twig
*
* Examples:
* - civicrm-entity--civicrm-event.html.twig
* - civicrm-entity--civicrm-event--teaser.html.twig
*
* @see template_preprocess_civicrm_entity()
{{ content }}
*/
#}
{% set classes = [
'civicrm-entity',
entity_type ? 'civicrm-entity--type-' ~ entity_type|clean_class,
view_mode ? 'civicrm-entity--view-mode-' ~ view_mode|clean_class,
] %}
<div {{ attributes.addClass(classes) }}>
<h1>Big Header</h1>
{{ content }}
</div>
# Example preprocess to engage field group or other modules when overridding template
/**
* Implements hook_preprocess_HOOK().
*/
function skvare_custom_bootstrap_preprocess_civicrm_entity(&$variables) {
if ($variables['entity_type'] == 'civicrm_contact' && $variables['view_mode'] == 'full') {
$variables['content'] = \Drupal::entityTypeManager()->getViewBuilder('civicrm_contact')->view($variables['elements']['#civicrm_contact'], 'default');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment