Member:
Markus ⋅
Date: February 27, 2010, 01:51 AM
⋅ Subject: "Re: Customizing box header."
By the way, if you want to do a bit more customizing before you output things, you can use <#INCL:my_custom_message.php#></#> (for example), and place a file into under /templates/includes/ where you just stick whatever you want to output under the variable $ext_input.
I frequently use this instead of attempting to tweak things together with the editor when I need to copypaste a large chunk of HTML, or if I need to do some simple evaluations before the content is printed out. Also, it's a sure way to keep less educated customers from messign things up. It's also an easy way to duplicate the same content in different units across pages without adding the info in several times. (Still working on "sticky" units that can be copied via builder, and there are the widgets too of course.)
If you used the above approach, you could do for example the following:
Create a blank file called my_mail_status.php. Inside it, place (for example) the following PHP code:
/* Here we evaluate the amount of a member's new mails */
if ($_SESSION['member']['member_unread_mail'] == 0)
$msg = "What a shame! No new mails today!";
elseif ($_SESSION['member']['member_unread_mail'] == 1)
$msg = "Grand! You got one new mail!";
else
$msg = "You're getting lots of mail these days! (Total {$_SESSION['member']['member_unread_mail']})";
/* Here we stick the message under the correct input variable to get everything passed onward */
$ext_input = <<<
<div class="general_wrapper">
<h3>Your Mail Status Report</h3>
<p>{$msg}</p>
</div>
WIC;
That gives you more control over what happens than hacking something like this together with the handy albeit limited template script would, since you have all the freedom of PHP at you disposal. Here's the above in a sample file you can grab and use or modify if you want to.
If you wanted to access all the data in the current unit that's being parsed (from your custom content to all of its builder choices to its database ID), it would be available to you under the variable $cache['current']['unit'] all across the system. (And for the current layout, it'd be under 'layout'.) You could for example check: if ( strstr($cache['current']['layout']['lay_ident'], "hello") === TRUE) ... else ... and then have the same bit on different pages, but make it behave one way on pages that have "hello" in the "show" variable of the URL, and another way for the rest of your pages.
If you wanted to include a little script such as above and create a unit that is visible only in certain situations (for example when new mail is available), you could declare $cache['current']['hide_this'] = true; after checking that mail counter is at zero, as we did above, and the unit would get hidden on the fly.
Since you're into usability, and you know your member base well, you could for example have a basic version of a message in $ext_input, a more verbose and elaborate version specifically for grandpa: if ($_SESSION['member']['member_username] == "Grandpa" || $_SESSION['member']['member_username] == "Grandma") $ext_input .= "Hey grandpa and grandma! Here's something more for you." --- how about that!
Or you could check, if ( (date("G") > 22 || date("G") < 7) && $_SESSION['member']['member_username] == "Little Jimmy") $ext_input = "Bedtime for kids! Check again tomorrow at seven.";
And if you should choose to tweak around with any of the above, I definitely want to hear what you've been up to! 