Skip to:
Content
Pages
Categories
Search
Top
Bottom

Need to customize my buddypress theme Template Stack


  • Pierre from DesignBots
    Participant

    @mecanographik

    Hi

    I request your help today for something quite simple (i expect).
    But i can’t find a working solution with the buddypress function ‘bp_register_template_stack’

    I need to change the last part of all my template stack url to target another folder in my theme « sage »
    this is because i’m using sage.io starter theme. The theme use the Laravel Blade templating system

    initial stack was :
    /app/public/app/themes/sage/resources/buddypress

    but i need to use :
    /app/public/app/themes/sage/resources/views/buddypress

    here is my try (in my functions.php) :

    /**
    * Buddypress template stack adaptation for Blade Sage.io templating
    * @link 
    * example @link http://www.generalthreat.com/2013/08/grappling-with-bp-theme-compatibility/
    *
    * maybe try: bp_locate_template to test the hook 
    * initial one was :
    * /app/public/app/themes/sage/resources/buddypress
    */
    
    function md_bp_blade_register_template_location() {
        // return STYLESHEETPATH . '/views/buddypress/';
        return TEMPLATEPATH . '/views/buddypress';
    
       // return '/app/public/app/themes/sage/resources/views/buddypress';
    }
    
    if( function_exists( 'bp_register_template_stack' ) ) {
     bp_register_template_stack( 'md_bp_blade_register_template_location', 1 );
    } 

    any idea how to make this function work?

Viewing 4 replies - 1 through 4 (of 4 total)

  • shanebp
    Moderator

    @shanebp

    So it was working before you changed the file location?

    And now, the error is what exactly ?

    afaik, TEMPLATEPATH is deprecated.
    Try using get_template_directory() or get_stylesheet_directory()

    And bp_register_template_stack should be hooked on bp_init.


    Pierre from DesignBots
    Participant

    @mecanographik

    Hi
    i can’t post my snippet on this forum … weird
    here is my gist :
    https://gist.github.com/mecanographik/156306079ed8c86e58ec9ef0472a31d6


    shanebp
    Moderator

    @shanebp

    Interesting problem… I’ve never used that theme.

    Just curious – under settings /wp-admin/admin.php?page=bp-settings
    which Template Pack is selected? Try switching it.


    Pierre from DesignBots
    Participant

    @mecanographik

    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/

    Any idea?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar