Partial Templates / Dynamically Insert Page Content

Right now it’s not currently possible to create a truly dynamic/scalable partial template in Bricks.

For example, let’s say you have a “Services” CPT that controls all your service pages. You want each Service page to have the same hero section layout, but then you want to customize the rest of the page in Bricks with the builder.

In Oxygen, you can create a template assigned to Services pages and add your hero layout to that template. You can then tell the template to dynamically inherit the page content for the rest of the template (meaning it will inherit whatever you build inside Bricks for each service page). They call this an “inner content” element, but really it’s just dynamically pulling whatever page content was created in the builder for that page/post.

In Bricks, you have to save the hero as a template section and then open up each service page individually and add a template element that references that template section. This isn’t nearly as scalable/maintainable because it requires manually editing every single services page. And if you ever want to remove the hero heading from all services pages, you have to edit each one individually again and remove it.

14 Likes

You won’t believe it! I was coming to this forum FOR THE FIRST TIME to ask exactly about this.

a. You solved my question (I needed to add the template on the page for it to show)
b. This method doesn’t make so much sense, because as it is right now the template works as a “reusable section” and not so much as a template (and as you point out, it is far from scalable).

Hopefully they find a better approach to this.

Love! :green_heart:

Couldn’t you just include your hero section in the header template for these pages and then enable conditions for the pages you want it to show on.

Exactly what i am waiting / hoping for. Really wondering if this will ever happen.
And yes this a very important when it comes to more complex pages.
Let’s see what they say. Really hoping for a better, more granular approach on templates.

This seems wrong.

Try:

  1. Create a services template i.e. with the hero section, sidebar etc. Add the post content element where you want the dynamic content from the services pages created in Bricks will be displayed and set it to output bricks content not WP content (inside the post content element).

  2. Assign this to the services pages via conditions.

  3. Create the pages in bricks (minus information held inside the template i.e. the hero section).

If you are using pages (for your service pages), you will need a way to target them in conditions. You can do this by adding tag support to pages and assigning a tag i.e. service

Code needed (not needed if saving your CPT is outputted with post capability):

// // add tag support to pages
function tags_support_all() {
	register_taxonomy_for_object_type('post_tag', 'page', 'post_type_faq');
}
// ensure all tags are included in queries
function tags_support_query($wp_query) {
	if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
}

// tag hooks
add_action('init', 'tags_support_all');
add_action('pre_get_posts', 'tags_support_query');
6 Likes

funny … so coding again. in oxygen easy doable, but yeah nocode… far away from userfriendly and easy.

read my post again

so yeah, no code needed :+1:

Yeah whatever. Kevin made it very clear what’s missing. And as i said for more complex pages it’s a must have.

You’re misunderstanding, Michael is saying what is being requested here is already possible in Bricks. It’s just different to Oxygen.

Instead of the inner content element, you instead use the ‘post content’ element and set the data source to ‘bricks’. If you do that for a services CPT, then you can create your hero section in your services template, and then create all service page using Bricks for the page content. They’ll inherit the service template hero section. You can then change the hero section in just one place, in the template, and all service pages will change.

6 Likes

Haha not really! :rofl:

If he does what he did in his video, then the solution is 100% super dooper easy, super user-friendly, and can be used on super duper complex pages, and guess what…WITH NO CODE. :rofl: :man_facepalming:

Safe warning…if you watch the video close your eyes between 48 mins and 53 mins because he used code :grimacing:

5 Likes

I flagged this post for deleting about 10 minutes after I created it. Unfortunately we can’t delete our own threads.

For some reason my brain was thinking the post content element was only for Gutenberg content. I totally didn’t realize it came with a dropdown for selecting Bricks content as an option. Once I saw that I tried to delete the feature request. Alas … can’t delete it :confused:

Thanks everyone.

9 Likes

Interesting, I learned something new! Thanks for sharing.

2 Likes

Thank you for explaining it in a simpler way. I will try this out :raised_hands:

Alright, I tried what I understood from this thread, but I couldn’t make it work. Let’s see if anybody can give me a hand on this.

Imagine that I want to create a floating contact section that goes on every page. I create a template as “section”, create the section on the template, add the condition to apply to the entire website. Then add a “post content” on the template, and set it to “Bricks”.

Still, I can see the floating section on the homepage, unless I add it manually from “templates”.

Am I missing something?

A couple of things…

  • the template type would need to be ‘single’, not ‘section’.
  • it will only apply on the homepage if you don’t have a front page template applied there. Otherwise, the front page template would override the single template that you created.

if you instead build your home page in Bricks, by editing the page in Bricks (not using a front page template) then you’ll see the section as inherited from the global template that you made.

It’s not as flexible as Oxygen’s, where you can go deep into nested templates or add priorities (it’s a flatter structure). But you can have a page or post made in Bricks, which is inheriting a template. (by adding the post content element in that template)

5 Likes

Alright!! that’s a clear explanation, thank you for taking your time :pray:t4: I think I get it. I will try and let you know.

If it works as expected, I will take away the first Bricks tutorial I did, so I can record it again, the template part was wrong.

Love :green_heart:

1 Like

So David. As I promised, I write again to let you know that I finally was able to make it work as expected :blush: it is not complicated at all, but yes confusing (at least coming from Oxygen). But the important thing is that it works, that you helped me immensely :pray:t3:‍, that now I understand the right way to do this, and that I will remake the first tutorial I made about Bricks in order to include this and other things I have learned over the days.

Really appreciate your help, much love! :green_heart:

@digitalgravy So good that you were not allowed to remove the post!!! :love_you_gesture:t4:

Great that the post could not be deleted, i picked up something new as well

3 Likes

Thats really good!!! :love_you_gesture:t4:

Older post reply - but for anyone else searching how to do something similar, in my case I wanted to check how to add a ‘repeatable’ section or ‘block’ (which could have been but wasn’t a ‘hero section’) of content on select pages to a new client site. So very similar to the above general scenario and so fast forward 2 years the other two easy (and great) ways of doing this are to:

  1. Create a new ‘section’ or ‘single’ template (in Bricks)
  2. Add your unique content (dynamic or static) in the template (either type)
  3. Insert that ‘template’/content via Bricks’ ‘template’ element/widget.
  4. Or you can use the template’s shortcode and use that (via Bricks’ ‘shortcode’ element).

The use case for me was to have the same content centrally editable but added into the flow of different pages at different page locations but you might also want to create ‘something’ that you intend to edit once (the Bricks template) but add to other site templates etc - all very nicely handled by Bricks - in case that helps anyone else.