Skip to main content

Drupal installation

Drupal Testimonials with a Custom Block

Drupal splits the job neatly. The script belongs in your theme as an external library, declared once. The widget itself is just an empty div, which fits in a content block that site builders can place in any region from Block layout.

  • An external library entry for the theme
  • The div for a content block body
  • Block layout placement and page visibility

Code generator

Code for your theme and your block

Enter the widget id. Parts 1 and 2 are edits to your custom theme, made once. Part 3 is the only thing that goes into the Drupal admin, and you can repeat it for every widget.

Shown in StoryProof when you copy a widget’s embed code.

Part 1 · Declare the script as an external library

mytheme.libraries.yml

# themes/custom/mytheme/mytheme.libraries.yml
storyproof-embed:
  js:
    https://app.storyproof.io/embed.js: { type: external, attributes: { async: true } }

Part 2 · Load that library on every page the theme serves

mytheme.info.yml

# themes/custom/mytheme/mytheme.info.yml (add to the existing file)
libraries:
  - mytheme/storyproof-embed

Part 3 · Body of the content block, in Source view

Content › Blocks › Add content block › Body

<div data-storyproof-widget="YOUR_WIDGET_ID"></div>

Clear the cache so Drupal reads the theme files again, place the block in a region, then view a page as an anonymous visitor.

The code is put together in your browser. Nothing you enter is sent.

The problem, solved

Where Drupal and embed code collide, and the split that avoids it

  • Problem 1

    The text format keeps eating my code

    Drupal text formats run filters over everything editors save, and the safer formats exist precisely to strip dangerous markup.

  • Problem 2

    I will not give editors Full HTML

    Drupal’s guide warns that script saved into content can be used against other visitors, and suggests keeping permissive formats for trusted users.

  • Problem 3

    Testimonials needed in a sidebar and a page

    Adding a script per block would load it twice on any page that shows both.

  • Problem 4

    Who decides which quotes appear?

    A testimonials content type in Drupal means typing and checking every quote inside the CMS.

  • Problem 5

    Visitors cannot submit one on the site

    Building a submission form with video upload and moderation in Drupal is a project of its own.

In StoryProof

Install it on a Drupal site

Step 1 of 5

Add the library to your theme

In your theme’s libraries.yml file, add the external script entry from Part 1, with async set as an attribute. Then list it under libraries in the theme’s info.yml file, as in Part 2.

Before you start

Drupal specifics

  • Your format must keep the attribute

    Whether the data attribute survives depends on how the chosen text format’s editor is configured on your site. If Source view no longer shows it after saving, use a format that allows it.

  • Placement is per theme

    Drupal’s guide notes that block placement is defined per theme. If you switch or add a theme, place the block again and add the library to that theme too.

  • Code access is required

    The library approach needs someone who can edit and deploy theme files. On a hosted Drupal with no theme access, ask your developer or host.

  • No Drupal module

    StoryProof is not a contributed module. The widget is embed code, and it shows a "Powered by StoryProof" badge until Pro.

  • Drupal docs as of 2026-11-13

    Paths follow the Drupal User Guide and theming docs on drupal.org as read on 2026-11-13. Nobody has followed these steps on a live site yet; older Drupal versions name the block library differently.

FAQ

Questions people ask

Short answers to what usually comes up next.

Can I put both lines in the block body instead?

Only if the block uses a text format that lets the script through. Drupal’s guide advises limiting permissive formats to trusted users, so the theme library is the safer home for the script.

Can I load the script only on some pages?

Yes. Instead of listing the library in info.yml, attach it with attach_library in the Twig template for the pages or block that need it.

Do I need a new block for every page?

No. One placed block shows in its region on every page unless you limit it with the page visibility settings. Create extra blocks only when a page needs a different widget.

Will this affect my Drupal page cache?

The div is static markup and is cached like any other block. The widget content is fetched in the visitor’s browser by the script.

Still have a question? Ask the StoryProof team or book a demo.

Bring real testimonials into Drupal

Collect and approve them in StoryProof, then place one content block wherever they belong.

Sources

  1. Creating a Custom Block, Drupal User Guide. Checked 2026-11-13.
  2. Placing a Block in a Region, Drupal User Guide. Checked 2026-11-13.
  3. Concept: Text Formats and Editors, Drupal User Guide. Checked 2026-11-13.
  4. Adding assets (CSS, JS) to a Drupal theme via *.libraries.yml, Drupal.org documentation. Checked 2026-11-13.

Last updated 2026-11-13.