20th Mar '23
/
0 comments

Button-specific HTML in Bricks Popup

In the Bricks Facebook group a user asks:

I need to create popups to expend the text (eg. read more). I wonder if I have to create separate Template for each popup or if there is a way to create 1 template and show different texts based on triggers.

There is currently no built-in option to pass text from the clicked button to the opened popup.

We can write JavaScript to grab the value of a custom data-popup-text attribute of our buttons and if not empty, set it as the HTML content of a text element inside the Popup.

This way, a single/the same Popup can be made dynamic for showing different content depending on which button is clicked.

This Pro tutorial shows how.

Step 1

Create a template of the type "Popup" and edit it with Bricks.

Settings (gear icon) → TEMPLATE SETTINGS → CONDITIONS: Add "Entire website" condition.

Add a Section and inside its Container, a Basic Text element.

Change the text to your desired default text/HTML that should appear when the popup is opened by clicking buttons that don't have our data attribute set.

Step 2

Create a Page and edit it with Bricks.

Add a button.

Add an interaction that will make your Popup show when this button is clicked.

Add a data-popup-html attribute and set its value to your desired HTML that should be shown inside the popup when this button is clicked.

Assign a class of say, popup-button. If you want to assign any styles to this class, you could add it in the element classes input box. Otherwise, at STYLE → CSS → CSS classes.

Duplicate this button and change the data attribute's value.

Duplicate the above button but this time, delete the data attribute.

Step 3

Page settings (gear icon) → PAGE SETTINGS → CUSTOM CODE → Body (footer) scripts.

Paste:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Switching Tabs on Hover in Bricks

Switching Tabs on Hover in Bricks

This Pro tutorial shows how to make the tabs of Tabs (Nestable) elements active on hover in Bricks. Step 1 Add one or more Tabs…
Categories:
How to sync two nestable sliders in Bricks

How to sync two nestable sliders in Bricks

In this tutorial, we'll learn how to sync two nestable sliders in Bricks: one will be the main slider and the other one will be…
Categories:
How to Create a Grid Slider in Bricks

How to Create a Grid Slider in Bricks

In this tutorial, we'll learn how to create multiple rows and columns inside the default nested slider of Bricks. Introduction A user recently asked in…
Categories:
Pro
Post Title at a Different Location on Image Hover

Post Title at a Different Location on Image Hover

This Pro tutorial provides the steps to update the text of a sticky div with the title of the post that is hovered on the…
Categories:
Pro
[WooCommerce] Sticky on Scroll Add to Cart section in Bricks

[WooCommerce] Sticky on Scroll Add to Cart section in Bricks

Setting up a sticky section that fades in when scrolling down and fades away when scrolled to the top.
Categories:
Setting Active Tab in Bricks’ Tabs (Nestable) Element

Setting Active Tab in Bricks’ Tabs (Nestable) Element

With Bricks' Nestable tab element, here's how we can set which tab is active by default.
Categories:
Pro
Viewport Entry Animation for all Sections Sitewide in Bricks

Viewport Entry Animation for all Sections Sitewide in Bricks

How to make viewport entry animations be automatically applied to either all sections of a page/template or sitewide across all pages.
Categories:
Pro
How to Link to a Specific Tab in Bricks

How to Link to a Specific Tab in Bricks

This Pro tutorial provides the JavaScript code that will automatically switch to the tab when using Nestable Tabs elements based on the "tab" URL parameter…
Categories:
Enqueueing a JavaScript File in Bricks

Enqueueing a JavaScript File in Bricks

Bricks child theme's functions.php comes with code to enqueue (load) style.css on the front end. What if you want to load a custom JavaScript file…
Categories: