Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Customize Buddypress Theme Template Stack
/**
* Buddypress template stack adaptation for Blade Sage.io templating
* @link https://roots.io/sage-9/
* example @link http://www.generalthreat.com/2013/08/grappling-with-bp-theme-compatibility/
*
* initial url was :
* /app/public/app/themes/sage/resources/buddypress
*/
// maybe see also : bp_locate_template to test hook
function md_bp_blade_register_template_location() {
// return '/app/public/app/themes/musicdata/resources/views';
// return STYLESHEETPATH . '/views/buddypress/';
return TEMPLATEPATH . '/views/buddypress';
}
if( function_exists( 'bp_register_template_stack' ) ) {
bp_register_template_stack( 'md_bp_blade_register_template_location', 1 );
}
@mecanographik

This comment has been minimized.

Copy link
Owner Author

commented Oct 12, 2018

Hi @shanebp
Thanks for your recommandations, you're right.
I've made it working by putting my snippet in bp-custom.php like this:

/**
* Buddypress template stack adaptation for Blade Sage.io templating
* @link 
* example @link http://www.generalthreat.com/2013/08/grappling-with-bp-theme-compatibility/
*
* initial one was :
* /app/public/app/themes/sage/resources/buddypress
*/

// will return something like '/app/public/app/themes/sage/resources/views';


function md_bp_blade_register_template_location() {
    // return STYLESHEETPATH . '/views/buddypress/';
    return TEMPLATEPATH . '/views';
}

// replace bp template parts syntaxe with the template overload from sage Blade types
// see: http://hookr.io/functions/bp_get_template_part/
function md_blade_replace_template( $templates, $slug, $name ) {

    // Overload the bp template
	
	$templates = array(); // empty it
 	
    if ( isset( $name ) ) {  
        $templates[] = $slug . '-' . $name . '.blade.php'; 
    }
    else {
        $templates[] = $slug . '.blade.php';
    }

    //print_r($templates);
    return $templates;
}

add_action( 'bp_init', function () {

	//error_log("bp init loaded");

	// custom url stacks for blade '/views' folder
	// working but Blade Syntax is not interpreted ...
	
    if( function_exists( 'bp_register_template_stack' ) ) {
        bp_register_template_stack( 'md_bp_blade_register_template_location', 1 );
    }
    
    // we also have to filter the render file extension (.blade.php) 
   // for Buddypress components tpl parts
	add_filter( 'bp_get_template_part', 'md_blade_replace_template', 10, 3 );

	// http://buddypress.wp-a2z.org/oik_api/bp_locate_template/
	//add_action( 'bp_locate_template', 'md_blade_locate_template', 1, 6);

});

But this technique doesn't work with bp ajax for example when bp groups loop is reloaded with ajax

I'm sure there is something to do with bp_locate_template() or bp_locate_template_and_load()
to inject correctly my buddypress templates in the_content from mytheme/resources/views/buddypress (instead of mytheme/resources/buddypress/)

By the way i'm using the Sage starter theme https://roots.io/sage/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.