0

Is there a way to render a node with view mode via token? Like:

[node:5:teaser]
  • Do you mean you want to know the API which can get the output from the token string? I guess you are looking for Token::replace – Jimmy Ko Jun 8 '16 at 18:34
  • @JimmyKo na I wanted to know if there was an existing text filter for that token, like insert view and insert block – Alex Jun 9 '16 at 8:02
  • Did you try token_filter? – Jimmy Ko Jun 9 '16 at 8:17
2

So the question is how to insert something like [node:5:teaser] into a formatted text area and get the teaser view of node 5.

This can be done with a combination of modules:

Token Filter (D7,D8)

Token Filter is a very simple module to make token values available as an input filter.

So (after adding that filter to the text format), for the current node, we can use e.g. [node:title] in formatted text.

Token Entity Render (D7, D8 Issue)

Provides tokens ([entity_type:render:view_mode_name]) that render full entities using view mode specified.

Advanced Entity Tokens (D7, D8 Issue)

Through AET you can query the DB for entities using Tokens. Examples: [aet:node:1]

Putting it together

In the end you should be able to use [aet:node:5:render:teaser] in your formatted text.

  • 1
    I'm amazed this is possible with tokens too, but I'd also suggest to consider the Entity Embed module for a use case like this. I'm using it successfully for media entities. – Hudri Jun 14 at 13:42
  • entity_embed - good point. Isn't most of this in media core these days anyway? – geek-merlin Jun 16 at 23:05

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.