Is this possible? I have looked into using the Token plugin and using PHP Code. I installed the Devel module and can see the array of variables available, but I can't get any actual variable data returned from the body using PHP. I have tried several enchantations of PHP 'print render' and print_r.

Thank you.

Comments

Superry’s picture

I kinda answered my own question...

under /drupal/filter/tips I found a 'hello world' sample that worked!

  $account = \Drupal::currentUser();
  if ($account->isAuthenticated()) {
    print t('Welcome @name! Thank you for visiting.', ['@name' => $account->getDisplayName()]);
  }
  else {
    print t('Welcome visitor! Thank you for visiting.');
  }

So I just have to figure things out a bit more and familiarize myself with the functions a bit more. What I'm trying to print are specific fields of content.

Superry’s picture

This is the answer to my question...

  $node = \Drupal::routeMatch()->getParameter('node');
  $value1 = $node->field_value1->value;
  $value2 = $node->field_value2->value;
amaclay’s picture

This is great, I've been wondering if this is possible for a while. Where did you drop this code in?