3rd Aug '22
/
3 comments

Mapping Bricks Templates to WordPress Templates

As of Bricks 1.5 RC, it is not possible to specify that a Page use a particular Bricks template without editing that Bricks template and setting a Condition.

This tutorial shows how we can create a custom Page template and link it to a Bricks template so that clients/editors can easily select a Bricks template without opening the Bricks editor and mucking around with conditions.

Use Case: In a site I am working on, the requirement is to have 3 pages for each of the 3 business’ store locations. ACF is being used for custom fields like Google map link, telephone number, address and these values are different for each store. While it is possible to use a CPT for this, let’s see how this can be set up using regular Pages.

We are going to continue with the above example. Feel free to adapt as needed.

Meta Box or any other custom fields plugin like Pods can be used instead of ACF.

First create your Bricks template named say, “Store Location”. For the time being, you could just add a Section having a test heading.

Create a file named page_store-location.php in the child theme directory having:

<?php
/**
* Template Name: Store Location
*/

get_header();

echo '<main id="brx-content">' . do_shortcode( '[bricks_template id="399"]' ) . '</main>';

get_footer();

Replace 399 with the ID of your Bricks template.

Create a Page titled say, “Store Location 1” and select the “Store Location” from the Template meta box.

Publish and visit the Page on the front end. You should now see the content of your Bricks template linked to the Page template that’s applied to this Page.

Now that you can confirm that the idea is working, create a ACF field group having your store location-specific fields and set the ACF location (meta box) rule to:

Page Template = Store Location

Now when editing any Page for which the “Store Location” WP Page template is applied to, this field group will appear.

Next, edit your Bricks template to set up dynamic data for outputting the values of these custom fields.

You could use the POPULATE CONTENT feature under Template settings to set your Bricks template to load one of your relevant Pages.

With this setup in place, the next time a new store location is added to the business, the client could simply create a new Page, select the WP template, fill in the custom fields and when they visit the Page on the frontend, it will be ready based on the chosen Bricks template.

In the next part, we may look into using ACF Pro and Meta Box for a dynamic select box that automatically loads all the Bricks templates such that picking one when editing any Page will link that Page to that Bricks template.

Get access to all 610 Bricks code tutorials with BricksLabs Pro

3 comments

  • Thanks, this helped so much!

  • This was one of the main reasons I doubt using Bricks in certain projects. Thanks!

  • Francois Gonin

    Thanks, this is a really helpful solution. I would like to achieve same thing for posts and custom post types. Tried different things without success. Renaming the templates seems not enough to get it work. Any Idea? ...only if it's not overcomplicating things. But I think it would be great if the customer can just choose between different post templates this way.

Leave your comment

 

Related Tutorials..

Pro
“Pro” Category Ribbon for Posts in Bricks

“Pro” Category Ribbon for Posts in Bricks

This Pro tutorial provides the steps to show a "Pro" ribbon for posts that are categorized under the "Pro" category when using Bricks builder. Step…
Categories:
Pro
ACF Repeater sub field value dynamic data condition in Bricks

ACF Repeater sub field value dynamic data condition in Bricks

This Pro tutorial provides the steps to output an element on single posts (can be of any post type) only if a specified ACF (Pro)…
Conditionally Outputting Elements only for Posts that have a Specific Taxonomy Term

Conditionally Outputting Elements only for Posts that have a Specific Taxonomy Term

Using the core WordPress has_term() function for checking if the current post has a specific term of a given taxonomy.
Categories:
Pro
Condition to Check if the Current Category Has At Least One Child

Condition to Check if the Current Category Has At Least One Child

Looking to render an element in the category archive Bricks template only if the category of the current category archive page is a parent? This…
Categories:
Pro
Bricks Dynamic Data Tag for Text-type Custom Field Value with Word Limit

Bricks Dynamic Data Tag for Text-type Custom Field Value with Word Limit

How to register a new dynamic tag for setting excerpt word limits and outputting an ellipsis (...) at the end.
Categories:
Dynamic Data :value filter in Bricks

Dynamic Data :value filter in Bricks

Bricks 1.5.7 introduced a new :value dynamic data filter. This tutorial provides a practical example of how this filter can be used. Meta Box Checkbox…
Categories:
Pro
Host Post’s Term in Bricks Query Loop

Host Post’s Term in Bricks Query Loop

Updated on 4 Mar 2025 In the BricksLabs Facebook group a user asked: Hi everyone, I’m facing a tricky situation that might have a simple…
Categories:
Pro
Conditional Output Based on ACF Date Field in Bricks

Conditional Output Based on ACF Date Field in Bricks

Updated on 1 Aug 2024 Looking to have a Section or other elements in Bricks rendered on the frontend only if today's date is before…
Categories: