Skip to:
Content
Pages
Categories
Search
Top
Bottom

Templates 1.2 – proper way to add components to profile home screen?

  • @egerrits

    Participant

    What is the ‘proper’ way to add a component to the user’s home screen? Right now the template 1.2 system loads single/home for the main screen and for the tabbed section home calls members/single/home, which includes hard coded calls to display its groups, invites, friends, blogs & activity templates. I want to add my own template there (events).

    Right now I have done this:

    bp_core_new_subnav_item( <shortened> 'screen_function'
    => 'events_screen_my_events', <shortend>) );

    To add My Events (0) to the tabs. In events_screen_my_events I have (just like in groups):

    bp_core_load_template( apply_filters
    ( 'events_template_my_events', 'members/single/home' ) );

    And, I added an action to ‘bp_after_member_body’ like such:

    function events_screen_list_events() {
    if ( bp_is_user_events() )
    locate_template( array( 'events/single/events' ), true );
    }
    add_action( 'bp_after_member_body', 'events_screen_list_events' );

    So, the sysmtem does go to members/single/home, but then my action kicks in and loads the events template at the right time.

    In events/single/events I copied the contents of members/single/groups.

    Is this the proper way to do these things? It just seems a bit back & forthy…

Viewing 3 replies - 1 through 3 (of 3 total)
  • @sbrajesh

    Participant

    hi Erwin

    A better way will be following the bp 1.2 style.

    So, you provide different filters for loading template, but all of them loads the same Index/home by default, which acts as a multiplexer using conditions as done in bp 1.2 theme.

    If you/a user really need to change this scheme, the filters can always be used to change template file.

    for example,

    //for loading user gallery Home page, I will do something like this in the screen function

    bp_core_load_template( apply_filters( 'gallery_template_my_galleries', 'gallery/index' ) );

    and for loading single gallery page I do something like this in the screen function

    bp_core_load_template( apply_filters( 'gallery_single_gallery', 'gallery/index' ) );

    So, both of these will load index which in turn loads further based on condition, but if a user do not wish to use hard coding in the theme with conditional, he can use the filters to manipulate this like

    add_filter("gallery_single_gallery","my_single_gallery_template");

    function my_single_gallery_template($template){
    return "gallery/single/index";
    }

    The reason I followed bp 1.2 style, It saves some typing and allows to reuse the layout+ I am trying to stick with the official style :)

    @egerrits

    Participant

    Thanks Brajesh, I see what you mean. I’ll try that.

    Any idea when/where to load the accompanying ajax/javascript?

    @sbrajesh

    Participant

    You are most welcome :)

    I will suggest putting javascript with template files, reason, the javascript is mostly dependent on template and will change in custom templates, so give the user the ability to customize without modifying the plugin.

    The problem for loading comes, when you want to activate your javascript function after activity is called, as Andy suggested in trac,

    https://trac.buddypress.org/ticket/1616

    Using ajaxStop for determining the case, though it is not the most efficient way. I am working on a custom javascript event thing, and if Bp1.2 is delayed for 2 weeks, I will put my solution for Andy’s review.

    In other case, using the wp_print_scripts action and wp_enqueue_script is your best recourse.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Templates 1.2 – proper way to add components to profile home screen?’ is closed to new replies.
Skip to toolbar