BuddyPress custom component, template issues
-
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 betweenmembers/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
- The topic ‘BuddyPress custom component, template issues’ is closed to new replies.