MyBB Community Forums

Full Version: Suggestion: basic conditional template variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I know that there is no conditional template options in 1.8 and below, but it would be very handy if there were simple variables that would help with more dynamic templates.

For example:
$mybb->template['loggedin'] = "yes"; // or no
$mybb->template['script'] = THIS_SCRIPT;

This way we can use CSS to hide and display html.

<div class="d-none loggedin_{$mybb->template['loggedin']}">
This can only be seen by logged in members.
</div>


<div class="d-none page_{$mybb->template['script']}">
Global templates can display page specific content.
</div>

It's not perfect, but saves having to hard code simple html depending on various conditions.
Try:
  • data-uid="{$mybb->user['uid']}" (and target in CSS with [data-uid="0"] for guests)
  • data-curentpage="{$current_page}" (and target in CSS with [data-curentpage="index.php"] for index.php)

Variable availability is template-dependent, though - e.g. {$current_page} is defined in global.php and would work in the header template, since it's also rendered in that file.
You learn something new every day. I've been trying to workaround simple conditions for ages.

Thank you Devilshakerz Smile