Skip to:
Content
Pages
Categories
Search
Top
Bottom

BuddyPress custom component, template issues

  • @stijndewitt

    Participant

    Hi BuddyPress community,

    I am developing a BuddyPress plugin with a custom BuddyPress component in it. So far I am working off the BuddyPress Skeleton Component, but that is a bit outdated. Mostly I have been able to work around the issues, but I have found myself stuck at this one issue.

    I am creating a new component called ‘bp-env’ with slug ‘env’. It has a custom screen in the user profile (main menu next to Activity etc called ‘Env’ with a submenu with currently just one screen, ‘General’) that I also want to show in it’s separate index page. It has an env/index template so we should be able to visit mysite.com/env and see the index page for the bp-env component. This is working somewhat, but only with some nasty hacks that I feel are probably not needed if I would just understand BuddyPress better.

    I have a function

    function bp_env_load_template_filter($found_template, $templates) {

    based on the one from the skeleton component. Inside that function I see this line:

    // note: this is only really relevant for bp-default themes as theme compat
    // will kick in on its own when this template isn’t found
    $found_template = locate_template(‘members/single/plugins.php’, false, false);

    I don’t really get what this does and I really wonder whether I don’t have to change the path given to locate_template. I don’t see any relationship between members/single/plugins.php' and my templates at 'my_plugin/includes/templates/buddypress/env/'... At that location I have anindex.phptemplate that should be able to show the screen for my env component when requested separately (e.g. via mysite.com/env) and ageneral.phpfor the 'General' screen for my component that is shown when we navigate toEnv / General` within the user’s profile.

    Below that line I added this code. It was the only way I see for now to make BuddyPress pick up my index.php template, but probably that’s just because I am a n00b… 🙂

    // get template from $templates array and strip the php extension
    $template = str_replace( ‘.php’, ”, $templates[0] );

    if ($template == ‘env/index’) {
    $found_template = CC_PLUGIN_DIR . ‘/includes/templates/buddypress/’ . $template . ‘.php’;
    return apply_filters(‘bp_env_load_template_filter’, $found_template);
    }

    $bp->env->template = $template;
    // add our hook to inject content into BP
    add_action(‘bp_template_content’, create_function(”, ‘
    global $bp;
    bp_get_template_part($bp->env->template);
    ‘));

    Eventually I got this to somewhat work by copying my page template into ../env/index.php, but I don’t think it is supposed to work this way. Inside the copied page template I now have this:

    <?php
    while ( have_posts() ) : the_post();
    ?>
    <article id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>
    <?php if ( ! is_front_page() ) { ?>
    <h1 class=”entry-title”><?php the_title(); ?></h1>
    <?php } ?>

    <div class=”entry-content”>

    <?php /*
    Here, we fill in the BuddyPress template. This should
    normally work by the page template requesting the_content()
    and BuddyPress selecting our template based on the URL,
    but we did not yet get this to work, so we do it hardcoded
    for now…

    // This code is not working atm…
    <?php the_content( __( ‘Read more →’, ‘ward’ ) ); ?>
    */ ?>

    <div id=”buddypress”>
    <?php do_action( ‘bp_before_member_home_content’ ); ?>

    <div id=”item-body” role=”main”>
    <?php do_action( ‘bp_before_member_body’ );

    // This should not have to be hardcoded I guess….
    bp_get_template_part( ‘env/general’ );

    do_action( ‘bp_after_member_body’ ); ?>
    </div><!– #item-body –>

    <?php do_action( ‘bp_after_member_home_content’ ); ?>
    </div><!– #buddypress –>
    </div><!– .entry-content –>

    <?php get_template_part( ‘content’, ‘footer’ ); ?>
    </article><!– #post-<?php the_ID(); ?> –>

    <?php
    comments_template( ”, true );
    endwhile;
    ?>

    As you can see I am completely copying both the page template from my theme (Ward) and the default BuddyPress code that renders the stuff around the screen on the Profile page…

    Any tips for where to look on how to do this properly would be greatly appreciated!

    -Stijn

Viewing 2 replies - 1 through 2 (of 2 total)
  • @stijndewitt

    Participant

    Sorry for the formatting issues. I apparently made a formatting mistake and don’t see a way to edit my post…

    @stijndewitt

    Participant

    Also, forgot to mention but I also have this (again modified from the example in the Skeleton):

    function bp_env_directory_setup() {
    	if (bp_is_env_component() && !bp_current_action() && !bp_current_item()) {
    		// This wrapper function sets the $bp->is_directory flag to true, which 
    		// helps other content to display content properly on your directory.
    		bp_update_is_directory(true, 'env');
    
    		// Add an action so that plugins can add content or modify behavior.
    		do_action('bp_env_directory_setup');
    
    		bp_core_load_template(apply_filters('env_directory_template', 'env/index'));
    	}
    }
    add_action('bp_screens', 'bp_env_directory_setup');
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘BuddyPress custom component, template issues’ is closed to new replies.
Skip to toolbar