Adding $name, $joindate, ect

Hey Guys,

So I've creatd a theme, but it's full of dummy text such as "Name here" and things like that. Can I just use the variabled in the default.php and the other pages so it would show say a username?

Thanks,

Vaughan

  • Basically, the answer is yes, you can use variables. But I don't think it makes sense to use variables in a theme (= look of site). Only if your theme would also include code for example to build up the login page, index page or other pages (filling them for example with widgets or other content) I would think it useful to include personalized elements there.

    $current_user = elgg_get_logged_in_user_entitiy();

    echo "Hello" . $current_user->name;

    would display "Hello <name>" for the currently logged in user with <name> replaced by this users Display name.

    Or better use

    echo elgg_echo(my_theme:hello), array($current_user->name));

    to be able to manage the text output via a language file which would also allow multi-language text output.

    In language file this would be defined for example as

    'my_theme:hello' => 'Hello %s',

    http://reference.elgg.org/ might be a starting point to look up available Elgg functions and their syntax. But you might also study the code of other plugins / theme plugins to learn more about Elgg functions and their use.

  • This is really useful, thank you. This is actually what I meant, not using just static variabled on their own. I couldn't really think of a way to describe it. I'm a front end developer, I know only the basics when it comes to back end programming/php! This is me trying to learn in a way I find useful. 

    So using it from a laungage file would be better? It seems that way from the way you've put it. So if I wanted to go back and change the way it's worded I wouldn't have to touched the index.php let's say but instead just go to the laungage file and change it there which would change the live code? 

    Thank you very much I'll have a read and tinker about!

  • Also, if I try say add your code, it wont load the site anymore, giving a default 'server error'.

    So adding <?php echo elgg_echo(theme:hello), array($current_user->name)); ?> in the default.php of the themes html it throw's an error.