Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Conditional Includes in Template Animation
When the user is not logged in:
<div id="content" class="noSidebar">
<div id="main">
<!-- STUFF GOES IN HERE //-->
</div>
</div>
Now imagine that for some really good technical reason, we need to remove that noSidebar class when we add a sidebar:
<div id="content" class="withSidebar">
<div id="main">
<!-- STUFF GOES IN HERE //-->
</div>
<div id="sideBar">
<!-- SOME OTHER STUFF GOES IN HERE //-->
</div>
</div>
The designer/template implementor simply creates two files:
my_interface.html
my_interface_logged_in.html
The developer then chooses which one to load according to whatever login system they're using:
if($security->loggedIn())
$template = $this->loadTemplate('my_interface_logged_in.html');
else
$template = $this->loadTemplate('my_interface.html');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment