Extend a view

Why this hook don't work:

if (elgg_is_logged_in()) {  

   elgg_extend_view("js/elgg", "js/my_script");

}

 

And how to extend some view (around js/elgg) for logged in users only?

  • It probably doesn't work because of caching - js/elgg gets cached - so if it's cached in the not-logged-in state that's how it will be presented until the caches are cleared.

    You can either check for logged in status in your js, or use elgg_register_js/elgg_load_js and have it in a separate file that gets loaded depending on logged in status.

    In terms of performance the first option is better.

  • In terms of performance the first option is better

    It was a reason for my question ;)

    Thanks, Matt!

  • @RVR : use 

    Wrap your condition using "elgg.is_logged_in()"

  • @Team Webgalli I knowed about it.

    As Matt said   problem is "js/elgg gets cached".

    Solved already with thease tricks:

    - Uncheck 'Use simple/system cache"

    - Flush the caches

    Works now ;)

  • @RvR - but you don't want to leave caching disabled...

  • @Matt Beckett  Sure :) I've turned on caching again

  • I'm really confused :(

    After some changes I got similar issue.

    This construction:

    if (elgg_is_logged_in()) {
        elgg_extend_view('page/elements/topbar', 'my/view'); //any system view
        elgg_extend_view('css/elgg', 'theme/css');
        elgg_extend_view('js/elgg', 'theme/js');
        }

    don't work with the simple caching.

    I did it into start.php of my theme.

    Also, I've tried it with js/css directly (as mentioned above)

    Just ignores elgg_is_logged_in()

    Without simple caching it's works as I want.

    The removing all files into data/view_simlecache can't helps.

    All privilages/rights are corrects (-R 755 www-data:www-data)

     

    Why the extending of the system JS/CSS with my own styles don't work even after flushing caches?

    What I missed?

  • It's happened on localhost (uses Apache w/o ext. mods) too. So I think that's an Elgg's issue not server' (uses Apache + mod_cache on production) or theme' settings.

    Priority (less than 500) parameter not works.

    I'm going try it with the simplecache view register hook now...

    Is it best solution than just elgg_extend_view function or not?

  • So.. The simplecache view function is returns the content no matter who is logged in..

    Issue is still to be ..

  • After ending of test here's the result:

    Function elgg_extend_view() don't append/prepend the custom views to css/elgg and js/elgg views providing:

    if (elgg_is_logged_in()) {
    elgg_extend_view('css/elgg', 'theme/css');
    elgg_extend_view('js/elgg', 'theme/js');
    }

    and return TRUE for non-logged users (they may to see the custom views) with enabled the simple caching (function elgg_is_simplecache_enabled())