Smarty Overview - Vanilla Success
<main> <article class="userContent"> <div class="embedExternal embedImage display-large float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6030677/uploads/095G828T2O4J/microsoftteams-image-288-29.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6030677/uploads/095G828T2O4J/microsoftteams-image-288-29.png" alt="MicrosoftTeams-image (8).png" height="108" width="1356" loading="lazy" data-display-size="large" data-float="none"></img></a> </div> </div> <h2 data-id="smarty-overview">Smarty Overview</h2><p>Vanilla currently supports both PHP and Smarty views. <a href="http://www.smarty.net/" rel="nofollow noreferrer ugc">Smarty</a> is a template engine that allows dynamic content to be inserted into a HTML template using tags. These tags are wrapped in curly braces: {tag}, and can represent variables or the output of a function call. They are replaced when the page is rendered. The default master view in Vanilla is a smarty template. See it in action by navigating to <code class="code codeInline" spellcheck="false" tabindex="0">/applications/dashboard/views/default.master.tpl</code>.</p><p>You can <a href="https://docs.vanillaforums.com/developer/addons/view-overrides/#the-master-view" rel="nofollow noreferrer ugc">override this view</a> in a theme or plugin, or by using the Custom Theme plugin which allows you to modify your current theme’s master view from the dashboard. This section will give you some ideas how you can customize your master view to suit your community’s needs.</p><h2 data-id="accessing-controller-data-with-smarty">Accessing Controller Data with Smarty</h2><p>You can output the content of the current page’s controller’s data array using Smarty by using <code class="code codeInline" spellcheck="false" tabindex="0">{$ArrayKey.NestedArrayKey}</code> syntax. For instance, <code class="code codeInline" spellcheck="false" tabindex="0">{$BodyClass}</code> in Vanilla’s master view outputs the css class names for the current page. <code class="code codeInline" spellcheck="false" tabindex="0">{$User.Name}</code> would render the session’s username. To see what data you have available to you on any given page, you can insert a <code class="code codeInline" spellcheck="false" tabindex="0">{debug_vars}</code> tag into your Smarty template and a popup listing the data in the data array will appear.</p><p><strong>Be very careful not to leave this feature on, as it can disclose personal information like email addresses.</strong></p><h2 data-id="smarty-functions">Smarty Functions</h2><p>In the default master view in Vanilla, you’ll find tags like <code class="code codeInline" spellcheck="false" tabindex="0">{searchbox}</code> which calls a function to render a search box in the page and <code class="code codeInline" spellcheck="false" tabindex="0">{breadcrumbs}</code> which calls a function to render the breadcrumbs. These are tags are mapped to php functions.</p><p>Some smarty functions in Vanilla can include parameters. For example, here <code class="code codeInline" spellcheck="false" tabindex="0">{breadcrumbs homelink="My Forum's Home"}</code>, the “homelink” parameter modifies the rendering of the breadcrumbs so that the “Home” breadcrumb renders as “My Forum’s Home”. Vanilla’s set of smarty functions that can be used in your template can be found by navigating to <code class="code codeInline" spellcheck="false" tabindex="0">library/SmartyPlugins</code>. The <a href="https://success.vanillaforums.com/kb/articles/235-smarty-functions" rel="nofollow noreferrer ugc">Smarty Functions section</a> documents these functions and their available parameters.</p><h2 data-id="smarty-conditional-functions">Smarty Conditional Functions</h2><p>Vanilla’s Smarty implementation has whitelisted a number of functions that can be used in Smarty conditional statements. For example, you can insert a Smarty tag or a snippet of HTML into your template only if the user is in a specific section or has a specific permission. These functions and how they can be used in your template, as well as a basic overview on using Smarty conditionals are outlined in <a href="https://success.vanillaforums.com/kb/articles/234-smarty-conditionals" rel="nofollow noreferrer ugc">Smarty Conditionals</a>.</p><h2 data-id="smarty-modifiers">Smarty Modifiers</h2><p>Smarty modifiers can be applied to variables, custom functions or strings. Vanilla-implemented modifiers and a general overview of modifiers can be found on the <a href="https://success.vanillaforums.com/kb/articles/236-smarty-modifiers" rel="nofollow noreferrer ugc">Smarty Modifiers</a> page.</p> </article> </main>