I have an entity template that starts like this:

<div class="<?php print $classes; ?>">
<h1><?php print $title; ?></h1>

But now I want to display the entity ID and the UUID next to the title. <?php print $entity_id; ?> or <?php print $entity_id; ?> display nothing.

Do I need to preprocess something?


$title is an available variable in that entity template. So, yes if you need to pass entity ID and UUID then you will have to pass them via preprocess hook.

  • Sorry can you elaborate on that..i'm in the learning phase ;-)
    – Yuri
    Sep 12 '17 at 19:13
  • can you try $entity->id to print the entity id?
    – Bharat
    Sep 13 '17 at 3:14
  • printing $entity->id gives no output
    – Yuri
    Sep 17 '17 at 16:29
  • can you try $entity->entity_id or $entity->eid
    – Bharat
    Sep 20 '17 at 8:30

It wouldn't display like that, firstly you would need to get the entity id then only you can print it after title. Now if it is a template of node then you can either just get the argument from the url e.g $node_id = arg(1); this will give you the node id and you can print this.

<?php print $node_id . ' ' . $title; ?> 

If it is some other entity then definitely in the url you will be getting some id of the entity.

Another way is that you can write hook_preprocess_page(&$variables) function where in $variables array you can set the value of the entity id e.g $variable['my_entity_id'] = ______ and in your template you can just print $my_entity_id . ' ' . $title;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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