programmatically display templates

Hey guys, is it possible to display a saved template without using BB interface by directly calling it inside a theme file?

Hey Viktor,

You could run a wp_query with the template’s post ID and then display it using the loop in a theme file. Does that make sense?

Justin

Now that you mention it, that makes perfect sense. What’s funny, it now also answers my other question about template importing/exporting. I completely forgot templates are custom post types.

Thanks a lot!

Ok, I tried using custom wp_query and was able to load the contents of the template but it strips away everything related to BB. As if it doesn’t exist. Here’s what I’m trying:

<?php
$args = array(
'p' => 373,
'post_type' => 'fl-builder-template');

$query1 = new WP_Query( $args );
if($query1->have_posts()) : while($query1->have_posts()) : $query1->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; wp_reset_postdata();  endif;?>

Is there anything specific I need to call?

Hey Viktor,

Sorry about that! I forgot to mention that assets are only loaded for posts in the main loop. You’ll need to use the fl_builder_global_posts filter to load in assets for posts in custom queries. Let me know if you have any questions about that.

Justin

Hey Justin, so by simply placing that function in functions.php and specifying page ID where to load BB assets it will work? There’s no additional changes to the custom query necessary?

Thanks a lot!

Hey Viktor,

Yes, you don’t need to make changes to the query. You’ll also need to specify the post ID of the template that you want to load assets for, not the page you are loading it on.

Justin

Ok, so here’s an issue. I do see now BB assets loading, after updating ID to template’s ID. But template’s CSS is not loaded. I see that template saves CSS to a custom file “373-layout.css”, I don’t see it being loaded. Is it supposed to load that file on all pages or does it combine everything into cached BB stylesheet?

Thanks,
Viktor

Hey Viktor,

Can you shoot me a link to the page where the CSS should be loading but isn’t? Also, can you paste your PHP code?

Thanks,
Justin

[Content Hidden]

Hey Viktor,

A CSS and JS file should be loading but neither of them are. Any chance I can get temporary FTP/Admin access to test?

Justin