Pretty new to php so bear with me.
I am using a simple template system where i set a variable as [%PLACEHOLDER%] that then outputs the data stored in the variable on the template page when ever i use the [%TAG%] associated with it.
I do this as i like to separate all of the php and html making it easier for different themes and templates to be created with out a user knowing php.
a simple example is :
(object) $tpl = new Tmpl( array( 'file' => 'templates/header.tpl' ) );
$tpl->replace( '[%USER%]', $user);
echo $tpl->output();
Now this all works fine. what i want to do is save a user session as a variable for me to assign a placeholder tag to it.
I use the following code with a php page
<div id="logedin" class="<?php echo (isset($_SESSION['sess_user_id'])) ? 'show' : 'hide'; ?>">
Welcome, <?php echo $_SESSION["sess_username"] ?>
basically if the user is logged in the div id 'logedin' is shown. if not its hidden.
there are 2 css styles i use for this.
.show{
display: block;
}
.hide{
display: none;
}
what i want to do is save the (isset($_SESSION['sess_user_id'])) ? 'show' : 'hide'; as a variable i can then assign as a placeholder.
something like this (but this obviously does not work hence me asking the question)
$sessionclassshow = (isset($_SESSION['sess_user_id'])) ? 'show' : 'hide';
$sessionclasshide = (isset($_SESSION['sess_user_id'])) ? 'hide' : 'show';
then i assign them as a place holder like this
$tpl->replace( '[%CLASSSHOW%]', $sessionclassshow);
$tpl->replace( '[%CLASSHIDE%]', $sessionclasshide);
so anywhere in my template file i can show or hide a div dependent on if the user is loged in or not.
<div id="topmenu" class="[%SESSIONHIDE%]"><a href="login.html">Login</a></div>
<div id="welcome" class="[%SESSIONSHOW%]">welcome [%USER%]</div>
so if the user is logged in hide the 'topmenu' div and show the 'welcome' div and vice versa.
I hope i have explained everything well enough and appreciate any help
thanks lee