Controller Assets - HL Vanilla Community
<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/3NDD97BCJXQ7/microsoftteams-image-288-29.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6030677/uploads/3NDD97BCJXQ7/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> <p>Assets organize content in a document. Assets are called by the main template (e.g. default.master.tpl) which renders the content currently stored in them. Assets are managed with code via plugins or the theme hooks file.</p><h3 data-id="default-assets">Default assets</h3><p>Vanilla uses these assets by default: <code class="code codeInline" spellcheck="false" tabindex="0">Head</code>, <code class="code codeInline" spellcheck="false" tabindex="0">Content</code>, <code class="code codeInline" spellcheck="false" tabindex="0">Panel</code>, and <code class="code codeInline" spellcheck="false" tabindex="0">Foot</code>. You cannot rely on every theme having a <code class="code codeInline" spellcheck="false" tabindex="0">Panel</code>, which is typically used as a sidebar. The <code class="code codeInline" spellcheck="false" tabindex="0">Content</code> asset is required, because it is where the view is rendered. You can, however, assign it additional content.</p><h3 data-id="using-assets">Using assets</h3><p>You can create your own arbitrary assets in your templates and simply add content to them using <code class="code codeInline" spellcheck="false" tabindex="0">Gdn::controller()->addAsset('AssetName', $content, 'ContentName')</code>. This is a great strategy for creating flexible themes that are easily customized by rearranging assets in the <code class="code codeInline" spellcheck="false" tabindex="0">default.master.tpl</code> file.</p><p>A common scenario is using <a href="https://success.vanillaforums.com/kb/articles/253-gdn-module" rel="nofollow noreferrer ugc">modules</a> to add content to an asset. (Note: In plugin hooks, you will typically be using <code class="code codeInline" spellcheck="false" tabindex="0">$sender</code> in place of <code class="code codeInline" spellcheck="false" tabindex="0">Gdn::controller()</code> since the sender <em>is</em> the controller).</p><p>You can set the sort order in which content in an asset is displayed via the <a href="https://docs.vanillaforums.com/developer/configuration" rel="nofollow noreferrer ugc">config</a>. Use a key like <code class="code codeInline" spellcheck="false" tabindex="0">Modules.{Application}.{Asset}</code> (e.g. <code class="code codeInline" spellcheck="false" tabindex="0">Modules.Vanilla.Content</code>) to define an array of <code class="code codeInline" spellcheck="false" tabindex="0">ContentName</code> values that you used when calling <code class="code codeInline" spellcheck="false" tabindex="0">addAsset()</code>. See <code class="code codeInline" spellcheck="false" tabindex="0">$ModuleSortContainer</code> in <code class="code codeInline" spellcheck="false" tabindex="0">Gdn_Controller</code>.</p> </article> </main>