Elgg not responding to views and languages folder of plugin

Hi all, i am new to elgg and learning to make a simple hello_world plugin from cash costello's book, i tried adding a languages and views folder but elgg doesnt seem to respond to that, can ne1 help?

I created a languages folder in root directory of the plugin with en.php, and views > default > plugin_name > temp.php file which i called from pages/world.php file using elgg_view() function...

Is there some other setting that needs to be done for elgg to understand that there is languages and view folder?

  • Elgg caches the locations of views and the language strings.  In order to have new stuff registered you need to clear the cache by going to the admin panel and clicking the 'flush caches' button on the control widget.

    When doing a lot of development though, it's easier just to turn of caching.  Do that in Admin -> Settings -> Advanced Settings

    Uncheck the boxes for system cache and simple cache.  Then it will register new views and language strings on every pageload.  Make sure to have caching turned on for any production environments though.

  • Thanks a lot Matt, it worked :)

    There's one more problem still, I had put the following in en.php

    $mapping = array(
    'hello:user'=>'Hello, %s',
    );
    add_translation('en', $mapping);

    and when i elgg_echo it using 

    echo elgg_echo('hello:user', elgg_get_logged_in_user_entity());

    it echos Hello, %s instead of replacing %s with logged in username. Any ideas of why its not working as expected?

  • @Deepak Sharma Try this:

    $user = elgg_get_logged_in_user_entity();

    echo elgg_echo('hello:user', $user->username);

  • @RvR oops actually i have used something like this one only,

    while trying to make long story short, I made a mistake, here's what all i have used:

    Plugin Name: hello_world

    "hello_world/pages/hello_world/world.php" contains :

    $user = elgg_get_logged_in_user_entity();

    $plugin_path = elgg_get_plugins_path();

    $params = array('name' => $user->name);

    $content = elgg_view('hello_world/greetings', $params);
    $vars = array(
     'content' => $content,
    );
    $body = elgg_view_layout('one_sidebar', $vars);
    echo elgg_view_page($title, $body);

    "hello_world/views/default/hello_world/greetings.php" contains :

    echo elgg_echo('hello:user', $vars['name']);

    "hello_world/start.php" contains :

    elgg_register_event_handler('init','system','hello_world_init');

    function hello_world_init(){
     elgg_register_page_handler('hello','hello_page_handler');
     $item = new ElggMenuItem('hello', 'hello', 'hello/world');
     elgg_register_menu_item('site', $item);
    }

    function hello_page_handler($page,$identifier){
     $plugin_path = elgg_get_plugins_path();
     $base_path = $plugin_path.'hello_world/pages/hello_world';
     require "$base_path/world.php"; return true;}

    now, everything's working fine, except, the problem that, i get Hello, %s instead of Hello, username when i load http://website.com/hello/world and i have specified correctly in hello_world/languages/en.php 

    $mapping = array(
    'hello:user'=>'Hello, %s',
    );
    add_translation('en', $mapping);

  • elgg_echo() still needs an array as the 2nd argument.

  • @Deepak Sharma Use my above code example in your hello_world/views/default/hello_world/greetings.php

    And in hello_world/pages/hello_world/world.php rewrite your code with it:

    $content = elgg_view('hello_world/greetings');

    $vars = array(
     'content' => $content,
    );
    $body = elgg_view_layout('one_sidebar', $vars);
    echo elgg_view_page($title, $body);

  • Thanks a lot vry1, shud have listened at first time, "array reqd as 2nd argument" Sry for such a silly question. :)

    changing $vars['name'] to array($vars['name']) made elgg_echo work in greetings.php :)

    @RvR: didnt try your way, but logic says that it will obviously work. Thnx for clearing my doubts.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking