« Back
Changing template layout with smarty
Posted by: mark | May 5, 2013 | Category: Smarty
I wanted to change some this sites layout depending on what was showing, remove the right side on blog detail for instance.
Or remove the page title, it also allows me to add a class to the main div so it can be full width.
For this I am using the blog title with assign and isset along with if and else statements.
At the top of the blog detail template we assign a variable. {assign var='alt_title' value=$entry->title} Now we can use isset to check if it is set (hence the name) in the page template, since the blog tag is in the {content} and the changes we want make are above it it will have to be moved up in the template and assigned a var to put it back in the flow, we will be using it two ways, one for adding a new class to the main div and one for removing the H2 with the Title tag. {content assign='stuff'} <div id="main"{if isset($alt_title)} class='wide'{/if}> {if isset($alt_title)}{else}<h2>{title}</h2>{/if} {$stuff} Father down in the template we will remove the right side, with 'nothing' between the isset tag and the else tag that is what will show. {if isset($alt_title)}{else} <div id="sidebar"> {content block='Sidebar'} {CGBlog action=browsecat summarytemplate='Sample'} </div>{/if}