I may be going about this incorrectly, if so please point me in the right direction.

I currently have a custom entity type and I'm adding the display fields via a controller class that extends EntityAPIController. I want to attach some content from elsewhere (non-entities) to the display of this custom entity.

I have an implementation of hook_theme:

function module_theme($existing, $type, $theme, $path) {
  return [
    'module_plugin_instance' => [
    'template' => 'module-plugin-instance',
    'path' => $path . '/templates',
      'variables' => [
        'instance_id' => NULL,

Then, in EntityTypeController::buildContent() I have:

$buildContent['module_plugin_instance_' . $instance_id] = [
  '#theme' => 'module_plugin_instance'

Where I'm failing is I can't figure out how to pass variables to the theme template here. The dummy html I'm putting in the template renders fine, just no variables. I've tried several different things, but I can't seem to get $instance_id to my template - what am I doing wrong?

1 Answer 1


You can provide theme variables through properties, e.g.:

$buildContent['module_plugin_instance_' . $instance_id] = [
  '#theme' => 'module_plugin_instance',
  '#instance_id' => 'foo',

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.