Is it possible to improve the tokens support in Layout Builder? It seems that at present only the most basic of tokens will render. E.g.

- In a Taxonomy Term Layout, custom block, [current-date:long] works but [term:name] does not.
- In a Node Layout, custom block, [current-date:long] works but [node:title] does not.

I understand this is down to the context that token/token_filter has. If these tokens can work, that it will make (to me at least) a huge difference to how useful LB is. One of the most useful aspects of panels, by comparison, is around using the contextual tokens, both as content and as Views contextual filter values etc.

??

Comments

bsarchive created an issue. See original summary.

cilefen’s picture

Version: 8.8.5 » 9.1.x-dev
Category: Bug report » Feature request

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

brooke_heaton’s picture

Is there any progress on this? Not being able to add a token for [node:title] in Layout Builder has to be among the dumbest bugs in Drupal 8/9.

tim.plunkett’s picture

This is a weird middle ground between feature request and bug report.

A custom block placed via the Block UI would have no way to use entity-specific tokens, even if you placed it only on a node or term page
(if that DOES work, then this is 100% a bug and should be a straightforward fix)

But of course when you're using LB on a node or term page, you expect the ability to use those tokens.


Either way, like all issues, this is only going to get resolved if someone takes the time to work on it.

brooke_heaton’s picture

FWIW, our workaround is to make our own token. Nid contextual arguments in views work, so it's befuddling why a token for a node would not work in a custom block in LB:

 /**
   * Getting the current Node Title.
   */
  public function getCurrentNodeTitle($current_node) {
    if ($current_node instanceof NodeInterface) {
      // Getting the title.
      return $current_node->label();
    }

    return '';
  }

The fact that the above is necessary seems just sad.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

tonytheferg’s picture

+1 for better token support in custom blocks.

A possible work around is also to build a block view with the relationships and all fields for all the tokens you want to utilize. Then instead of using the custom block from LB, use the custom text from views for the markup, and insert in the view into the Layout.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

anybody’s picture

+1 on this, just had the same need.

As it seems, contrib tries to solve this: https://www.drupal.org/project/entity_token_block
But for me it currently doesn't work well (#3468068: Provides "User" and "Product variation" entity token block types on taxonomy term layout builder) and seems a bit hacky?

So a general core solution would be much better.

anybody’s picture

Title: Tokens in layout builder » Tokens in layout builder / content blocks
aram.gevorgyan’s picture

Hi , before this will be fixed, I have created workaround module which is really simple and can help you, module is adding Ckeditor filter and checking current url is node or group and doing token replace, please try https://www.drupal.org/project/node_token_filter, if in some cases it will not work please give me some feedback and I will take a look, I hope this will resolve your issues.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.