Don’t Repeat Yourself. It’s a rule that we learn for writing code. And guess what: it applies just as well to writing content. If you copy and paste the same thing in lots of places, it’s going to be a real hassle if you need to go back and change it later.
I’m building a Drupal website to share info about food pantries in my area. As I began entering data about pantries, I realized that I was copying and pasting text across nodes more than I wanted to. Each pantry has distinct eligibility requirements, yet many pantries have certain pieces in common. I wanted to be able to write out the eligibility requirements as freeform text but intersperse it with canned text.
Here’s how I set up a toolbar button in CKEditor that inserts boilerplate text:
Step 0: I’m going to assume you already have a formatted text field that you want to insert boilerplate text into, and that you have its text format set up to use CKEditor.
Step 1: Create a taxonomy vocabulary for the boilerplate text.
The term labels will hold a brief description of the text. Add a formatted text field for the full text. Configure its allowed text format to match the formatted text field that you’ll be inserting boilerplate text into.
In the vocabulary’s default display, hide the built-in Description field. Hide the label for your formatted text field.
Add some terms to the vocabulary.

Step 2: Install the Entity Embed module.
Step 3: Create an entity embed button.
- Go to Configuration > Content authoring > Text editor embed buttons.
- Click “Add embed button”.
- For “Embed type”, select “Entity”.
- For “Entity type”, select “Taxonomy term”.
- For “Vocabulary”, select the one you just created.
- For “Allowed Entity Embed Display plugins”, select “Taxonomy term page”. (This will use the default display mode.)
Step 4: Add the entity embed button to CKEditor.
- Configuration > Content authoring > Text formats and editors.
- Click the “Configure” button for the text format that you want to add the button to.
- Under “Toolbar configuration”, locate the button you just created. If you didn’t set an icon, it will have “E” as its icon. If you see two buttons with “E” icons, hover over them to see which one is yours.
- Under “Enabled filters”, check the box for “Display embedded entities”.
Result: Now you have a CKEditor toolbar button that will insert boilerplate text.

When you click the button, it asks you to select a term. Type in part of the term’s label and pick from the autocomplete options.

In the next dialog, just click Embed.

And it inserts the boilerplate text.

There are a couple more things you might want to do to polish this off.
Step 5: Adjust your theme’s CSS as needed to get the spacing around the boilerplate text right.
Step 6: Install the Rabbit Hole module and configure it to disallow visiting taxonomy term pages for the vocabulary you just created.
At the heart of all of this is the concept of entities in Drupal. Entities are how you encapsulate and reuse content, how you display the same content in different ways and different places, so that you Don’t Repeat Yourself.
Jaymie Strecker is a web developer and one of the six entities who comprise Kosada.
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.