SimplePortal

Support => English Support => Topic started by: Chas on July 23, 2010, 11:08:11 AM

Title: Using variables in blocks
Post by: Chas on July 23, 2010, 11:08:11 AM
Hi.

I have set up a block to show just on the Welcome New Members board (a BBC block) and I want to use a system variable in it like {$member.name} - The current member's name. (for personalization.)

I have tried using BBC and HTML blocks to no avail, the text {$member.name} shows not the actual members name.

Is there a way to use a variable within a block?

Thanks.
PS tried searching for the answer but could not find any relating to variables.
Title: Re: Using variables in blocks
Post by: 130860 on July 24, 2010, 08:04:00 PM
it may be done with a php block, for example:


global $context;

$variable = 'your message here:  hi {username}  welcome to my forum';

// we parse $variable so we can use bbc on it.

parse_bbc($variable);


$variable = str_replace('{username}', $context['user']['username'], $variable);


this will replace {username}   with the name of the user.

and then  echo $variable:


echo $variable;


hope that helps
Title: Re: Using variables in blocks
Post by: Chas on July 25, 2010, 05:06:57 AM
Many thanks 130860, that's just what I need.

Cheers

Hal
Title: Re: Using variables in blocks
Post by: 130860 on July 25, 2010, 02:41:32 PM
glad it worked, marked as solved then :)
SimplePortal 2.3.8 © 2008-2024, SimplePortal