Skip to main content
added 190 characters in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

The node title already has a token, you can see this, if you install the token module: https://www.drupal.org/project/token

This is only an alpha version, but it is OK to use it.

Go to the help page of the module and you will see that the node title is already there:

[node:title]

You can use this token only in a node context. If you use it outside of this, for example in a block, you have to add a cache context in this block:

$build['#cache']['contexts'][] = 'url.path';

And a cache tag to invalidate the block if the node is changed:

$build['#cache']['tags'][] = 'node:N';

or if any node is changed:

$build['#cache']['tags'][] = 'node_list';

The node title already has a token, you can see this, if you install the token module: https://www.drupal.org/project/token

This is only an alpha version, but it is OK to use it.

Go to the help page of the module and you will see that the node title is already there:

[node:title]

You can use this token only in a node context. If you use it outside of this, for example in a block, you have to add a cache context in this block:

$build['#cache']['contexts'][] = 'url.path';

The node title already has a token, you can see this, if you install the token module: https://www.drupal.org/project/token

This is only an alpha version, but it is OK to use it.

Go to the help page of the module and you will see that the node title is already there:

[node:title]

You can use this token only in a node context. If you use it outside of this, for example in a block, you have to add a cache context in this block:

$build['#cache']['contexts'][] = 'url.path';

And a cache tag to invalidate the block if the node is changed:

$build['#cache']['tags'][] = 'node:N';

or if any node is changed:

$build['#cache']['tags'][] = 'node_list';
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

The node title already has a token, you can see this, if you install the token module: https://www.drupal.org/project/token

This is only an alpha version, but it is OK to use it.

Go to the help page of the module and you will see that the node title is already there:

[node:title]

You can use this token only in a node context. If you use it outside of this, for example in a block, you have to add a cache context in this block:

$build['#cache']['contexts'][] = 'url.path';