0

I'm trying to reduce repetitive coding by adding my own static HTML content into some form of reusable token that can be added into page bodies amongst regular code, but can't find a method. Here's what I'm looking for:

Desired content to be inserted into page body

<div class="my-repetitive-div">
    <p>I type this all the time and want to automate it</p>
</div>

Token idea to insert this into a page Body

<p>Here is some regular content</p>

[token:my-repetivie-div]

<p>and some more content appearing after my-repetitive-div</p>

End result

<p>Here is some regular content</p>

<div class="my-repetitive-div">
    <p>I type this all the time and want to automate it</p>
</div>

<p>and some more content appearing after my-repetitive-div</p>

This question is similar to this one, but he didn't quite get a straight answer, so I'm spelling it out here.

The Token Filter module wasn't what is needed, as it only addresses using pre-existing Tokens not creating custom ones. Would the Custom Token module achieve this?

If there's a better way to achieve this other than Tokens, i'm all ears!

1

I would recommend you to use Wysiwyg API template plugin module

In TinyMCE, CK Editor and FCK Editor, there is a template function, which allows a user to select a HTML template from a drop-down and insert it into the WYSIWYG text-area. This module supports those features for use with the WYSIWYG API.

| improve this answer | |
0

It looks like the Custom token module was what I needed. It delivers the exact functionality I described, with slightly different syntax:

[custom:token-machine-name]

Once installed, you can create your own tokens to allow referencing repeatable content under /admin/structure/token-custom. Changes to your tokens are immediately propagated everywhere the token is referenced.

Note that the Custom Token module requires the Token Filter module to operate, and for your chosen text format to have the Replace tokens option checked to process the tokens correctly.

This option can be found under the 'Filter' heading on /admin/config/content/formats/my_chosen_text_format

| improve this answer | |

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.