50% discount on BricksLabs Pro Membership Lifetime Access. Use coupon: GOBRICKS

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.

  • 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