I’ve been working a lot lately with generating emails from within Drupal. I was asked how to create a Token of a piece of Drupal content (a Node). Even when not coding in Drupal — tokens can be very useful! A token in Drupal-lingo is:
Tokens are small bits of text that can be placed into larger documents via simple placeholders, like %site-name or [user]. The Token module provides a central API for modules to use these tokens, and expose their own token values.
Modules may provide their own tokens using drupal Hooks. As of Drupal 7 Tokens are apart of Drupal-core.
But, the ability to create a token of a full Node view is not possible out of the box. Thankfully, with a bit of searching we can find a Community module that provides this feature to our website. The Advanced Entity Token (AET) provides tokens for entities and their view modes:
[aet:node:1] will return the 1st node with the token view mode (or full if token is not available).
[aet:file:1:view-original] will return the 1st file entity with the original view mode.
[aet:taxonomy_term:1:name] will return the 1st node title field (note that this level of chaining is done by the formal token implementation of the node entity in token/token.tokens.inc -> token_token_info()).
So by using the AET you could create an email template Node Type, which could use Tokens too by the way, which is a Drupal node (content) that you could then embed in a piece of outgoing email by using this node as the message body using [aet:node:NID]. If you don’t want these email template node(s) to not show up on your site from Google or site searches I recommend using the RabbitHole module.