The Bootstrap Paragraphs module provides a suite of content and layout Paragraph bundles made with the Bootstrap front-end framework.
Paragraphs is a contrib module for Drupal that allows creation, administration, and display of customizable content components.
Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web.
How many times have you built...
How many times have you built it just a little bit different???
Install this module on a test site and start exploring all the possibilities Paragraphs offers.
Thanks to Les Lim and David Needham's great presentation Using Paragraphs to Weave a Beautiful Content Tapestry, I learned the idea of separating paragraph bundles into Content, Layout and Ponies categories.
This idea helped me solidify the structure of this module.
Every paragraph, whether content or layout has the option to set background color and one of five widths, from narrow to full using List/Text Select fields.
Each Paragraph has an option where you can set one of 5 widths. As the width gets narrower, the content becomes centered using Bootstraps offset classes. The widths are:
Each Paragraph has a background color option. Included are over 50 background colors and five empty background classes for you to customize in your own theme.
Empty classes follow the Bootstrap nomenclature:
Common semantically organized fields, and reference fields to common entities.
Entity Reference Revisions fields to other Paragraphs.
This Paragraphs type has a formatted long text field, which we configured to use the Full HTML text format during installation. This is essentially what you would expect from a normal body field.
This Paragraphs type has an Image reference field, and a Link field if you want to link the image. Because this uses Drupal core's Image module, we get to set the default field attributes, and require an ALT tag, which is required for proper accessibility.
The Blank Paragraphs type is perfect for less restrictive HTML and JavaScript. I use these paragraphs for things like scripts from external services like Mailchimp, Pardot, Eloqua, Marketo; and adding page specific JSON-LD for SEO.
The Drupal Block Paragraphs type has a reference field to Drupal core, System, and Menus blocks for easy inclusion in your content.
You can also use this type as an example for creating a Paragraphs type for your custom blocks.
Some Drupal blocks do not render. Here is the list of working/not working blocks as of October, 2017.
Working
Not Working
The Bootstrap Paragraphs Views type allows you to easily embed a View in and around your other Paragraphs using a Views Reference Field.
The three Bootstrap Paragraphs Column types allow content creators to add column structure into their content using a Column Content field.
The field allows for multiple values, so columns can be easily reordered by drag and drop in the admin UI.
Allows you to add multiple Paragraphs in a column. Basically, it is another level of nesting, if you need to add an image and a simple to a column.
Works in all three column types.
The Bootstrap Paragraphs Carousel allows for other Paragraph entities to be loaded in the Slide Content field. Cycle through images, simples, or multi-column pieces of content. The Carousel also has a Slide Interval speed option.
The Bootstrap Paragraphs Accordion implements the Bootstrap Collapse Javascript to create an accordion with the panel/card component. The Accordion references the Accordion Section Paragraph Type which has a title and a Paragraph reference section for the accordion body.
The Bootstrap Paragraphs Modal allows for content creators to easily add modals to the site.
The bundle has 4 fields:
The Bootstrap Paragraphs Tabs lets you put Paragraph entities in different tabs using the Tab Section bundle.
The Bootstrap Paragraphs Contact Form submodule installs a Paragraph bundle that allows you to embed one of Drupal 8 core's Contact Forms anywhere you need it, including inside of Accordions, Carousels, Columns, Modals, and Tabs. This is possible thanks to the Contact Formatter module.
Add Inline Entity Form to allow your administrators to add new, or select existing Contact Forms.
The Bootstrap Paragraphs Webform submodule installs a Paragraph bundle that allows you to embed a Webform anywhere you need it, including inside of Accordions, Carousels, Columns, Modals, and Tabs.
.row
rules.container
or .container-fluid
.paragraph-type--type
.paragraph--view-mode--default
.paragraph--width--name
.paragraph--color
.paragraph--color--color-name
We apply the appropriate Bootstrap widths here.
{{ content|without('bp_width', 'bp_background') }}
The content is added without the background color and width fields.
In our Paragraphs templates we use a libraries to load the CSS files only on pages that need it.
{{ attach_library('bootstrap_paragraphs/bootstrap-paragraphs') }}
{% if paragraph.bundle == 'bp_columns' %}
{{ attach_library('bootstrap_paragraphs/bp-columns') }}
{% endif %}
Additional libraries are loaded in specific bundle template files.
{{ attach_library('bootstrap_paragraphs/bootstrap-paragraphs') }}
{{ attach_library('bootstrap_paragraphs/bp-tabs') }}
All libraries are loaded minified. Specialty libraries have the preprocess: false; flag which means they will be loaded by themselves and not part of the aggregated CSS.
bootstrap-paragraphs:
css:
component:
css/bootstrap-paragraphs.min.css: { minified: true }
css/bootstrap-paragraphs-columns.min.css: { minified: true }
css/bootstrap-paragraphs-colors.min.css: { minified: true }
bp-accordion:
css:
component:
css/bootstrap-paragraphs-accordion.min.css: { preprocess: false, minified: true }
dependencies:
- core/jquery
bp-carousel:
css:
component:
css/bootstrap-paragraphs-carousel.min.css: { preprocess: false, minified: true }
dependencies:
- core/jquery
bp-columns:
css:
component:
css/bootstrap-paragraphs-columns.min.css: { preprocess: false, minified: true }
bp-columns-two:
css:
component:
css/bootstrap-paragraphs-columns-two.min.css: { preprocess: false, minified: true }
bp-columns-three:
css:
component:
css/bootstrap-paragraphs-columns-three.min.css: { preprocess: false, minified: true }
bp-image:
css:
component:
css/bootstrap-paragraphs-image.min.css: { preprocess: false, minified: true }
bp-modal:
css:
component:
css/bootstrap-paragraphs-modal.min.css: { preprocess: false, minified: true }
dependencies:
- core/jquery
bp-tabs:
css:
component:
css/bootstrap-paragraphs-tabs.min.css: { preprocess: false, minified: true }
dependencies:
- core/jquery
For Full Width Colors, add a new Region into your page.html.twig
{% if page.structured_content %}
{% block structured_content %}
{{ page.structured_content }}
{% endblock %}
{% endif %}
And add the following CSS to your theme.
/* Adds full width, margin-less and padding-less container for Paragraphs. */
/* This is so colors go full width. Padding is on interior elements. */
.structured-content.container {
padding-left: 0;
padding-right: 0;
width: 100%;
}
Customize Bootstrap Paragraphs in your own theme after you've installed.
After installation, Paragraph Bundles and Fields are kept in your database and in your configuration.
Any changes you make will be yours.
Your theme has a higher priority than this module. Move the template files, and Overwrite the CSS from your theme if desired.
In fact, you can uninstall this module after installation and still keep all the functionality.
attach_library
calls.Use the Drupal Block Paragraph to provide the example.
Add a new Paragraph Type.
Add the existing Background field.
Add the existing Width field.
Add a new Reference Revisions field, select Other for type.
Select Custom Block in the Reference Revisions field settings.
Select which Custom Block Type Bundles.
Manage Display
Spin up a sandbox on your favorite hosting platform or on your local dev environment and build your functionality.
Install, Test, & Share the finished product
Using frameworks benefits productivity (Drupal, Bootstrap, Paragraphs). That is what I was trying to achieve by building these modules.
You can also use this approach with other front end frameworks and scripts -- Singularity, Foundation, Slick, etc...