Smarty Master View
This master view acts as the wrapper for each page in your theme. Often, this is the only view you'll have to manipulate. The master view file is called the default.master.tpl
(Smarty template) or the default.master.php
. We recommend using Smarty templates for your master view, however you can decide to use a regular ol' php view if you like.
To override the default master view:
- Create a new file called
default.master.tpl
(or default.master.php) - Place it in the views folder in your theme folder (i.e.,
/themes/{your_theme_name}/views/
)
If you're new to this, it's probably a good idea to copy the content of /applications/dashboard/views/default.master.tpl
into your theme's master view and manipulate it from there.
Smarty tags in the master view
You can accomplish a great deal of things using Smarty in your default master view. We highly recommend checking out our complete Smarty docs to get a bearing on this, but here's what you need to know to get started.
Required tags
There are a few assets that need to appear and an event that needs to be fired from your master view in order for everything to run smoothly. The contents of these tags are programmatically generated, depending on your forum's data and configuration. Omitting any one of these tags may result in some strange behaviour on your forum.
- The head asset
{asset name="Head"}
This should appear within the head <head>
block of your html. It contains the css and javascript needed for your applications and plugins. - The content asset
{asset name="Content"}
This should appear within the body <body>
block of your html. It contains the main content of any page. - The panel asset
{asset name="Panel"}
This should appear within the body <body>
block of your html. It generally adds tertiary functionality to the forum, however it does include necessary functionality for the Profile and Conversation sections of forum. If you decide to go with a panel-less design, we recommend using css to hide the panel on pages where it's unnecessary or to manually adding the panel into the forum sections where it is necessary using the inSection function (see the More Smarty tips and tricks section below for an example of this). - The foot asset
{asset name="Foot"}
This should appear after the Content asset within the body <body>
block of your html. Plugins and applications add content or scripts to this asset. - The AfterBody event
{event name="AfterBody"}
This should appear just before the closing body tag </body>
of your html. Plugins and applications hook into this event to generate content.
Useful tags and practices
- Searchbox
{searchbox}
Adds a handy little searchbox. - Breadcrumbs
{breadcrumbs}
Adds breadcrumbs, a crucial detail when navigating a forum. - The Me module
{module name="MeModule"}
Adds the Me module. This module contains dropdowns for notifications, bookmarks, conversations and settings. It helps a logged-in user access what's important to them. - Opening body tag
<body id="{$BodyID}" class="{$BodyClass}">
This is how we recommend opening your body element. It adds programmatically generated CSS classes and ids to the body block, which are very useful for targeting sections when styling your forum.
The most up-to-date set of Smarty functions and modifiers can be tracked down in /library/SmartyPlugins
.
More Smarty tips and tricks
- Signed in users You can add content to your forum depending on whether a user is signed in or not. For example:
{if $User.SignedIn}Welcome back!{/if}
This snippet adds a welcome message for any signed in user. - Forum sections You can add content to your forum depending on what section you're in. For example:
{if inSection(['Profile', 'Conversation'])}{asset name="Panel"}{/if}
This snippet adds the panel asset to the Profile and Conversation sections of the forum. You can find the section name of any page in the forum by using your browser's web tools to inspect the body element. One of the CSS classes on the body element will be Section-*, where * is the section name. (Assuming you have adhered to the opening body tag tip above.)
Smarty variables and setting page data (Advanced)
If you've read this far, you may have noticed we've used some variables above to determine the logged-in state of the user ($User
) and to add body classes to and ids to the body tag ($BodyID
and $BodyClass
). You'll probably not be surprised to learn that there are even more variables you can access and use!
For use in testing environments only, to view all the variables you have access to, you can include a special tag anywhere in your default master view: {debug_vars}
After adding this tag, refresh your forum page in a browser. A popup will show all the data variables available for use on the given page (you gotta make sure your browser's allowing popups here).
To go even further, you can use event handlers to assign data to variables that you can then use in your view.
Smarty default master view example
To see how it all fits together you can check Keystone (one of our core themes) master view.