View Helper Functions - 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/8FJGJERRERPZ/microsoftteams-image-288-29.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6030677/uploads/8FJGJERRERPZ/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>This is a quickstart guide to some of Vanilla’s globally available functions and methods. Familiarizing yourself with them will save you time and effort in the long term, and give you clues about how best to use the framework.</p><p>This is by no means an exhaustive list, nor full signature documentation. You’ll want to find them in the source code (files at <code class="code codeInline" spellcheck="false" tabindex="0">/library/core/functions.*.php</code>) for more info.</p><h2 data-id="getting-setting">Getting & setting</h2><p>See <code class="code codeInline" spellcheck="false" tabindex="0">functions.compatibility.php</code> for more info.</p><ul><li><code class="code codeInline" spellcheck="false" tabindex="0">val()</code> allows the retrieval of a named key or property from an array or object, and optionally provide a default if the named item does not exist (default: <code class="code codeInline" spellcheck="false" tabindex="0">false</code>). This is helpful when you’re unclear whether a key/property is set, or what data type you have currently. This function was previously named <code class="code codeInline" spellcheck="false" tabindex="0">GetValue()</code>, which is now deprecated.</li><li><code class="code codeInline" spellcheck="false" tabindex="0">setValue()</code> is the opposite of <code class="code codeInline" spellcheck="false" tabindex="0">val()</code> - it sets the named value on the array/object with the specified value.</li><li><code class="code codeInline" spellcheck="false" tabindex="0">Gdn::get()</code> retrieves a key from the <code class="code codeInline" spellcheck="false" tabindex="0">GDN_UserMeta</code> table with a UserID of 0. This is used for generic data storage, especially large, plugin-related settings.</li><li><code class="code codeInline" spellcheck="false" tabindex="0">Gdn::set()</code> places data into the <code class="code codeInline" spellcheck="false" tabindex="0">GDN_UserMeta</code> table with the given key against UserID 0.</li></ul><h2 data-id="configuration">Configuration</h2><p>See <code class="code codeInline" spellcheck="false" tabindex="0">functions.general.php</code> for more info.</p><ul><li><code class="code codeInline" spellcheck="false" tabindex="0">c()</code> grabs a value from the configuration with the option to provide a default (<code class="code codeInline" spellcheck="false" tabindex="0">false</code> if none is provided).</li><li><code class="code codeInline" spellcheck="false" tabindex="0">saveToConfig()</code> saves a value to the config. Pass <code class="code codeInline" spellcheck="false" tabindex="0">false</code> as the third parameter to only set the config for the current runtime.</li></ul><h2 data-id="html">HTML</h2><p>See <code class="code codeInline" spellcheck="false" tabindex="0">functions.render.php</code> for more info.</p><ul><li><code class="code codeInline" spellcheck="false" tabindex="0">url()</code> generates a valid, full URL for a resource on your site.</li><li><code class="code codeInline" spellcheck="false" tabindex="0">externalUrl()</code> generates a valid URL to a resource not on your current site.</li><li><code class="code codeInline" spellcheck="false" tabindex="0">anchor()</code> creates an HTML link.</li><li><code class="code codeInline" spellcheck="false" tabindex="0">img()</code> creates an <code class="code codeInline" spellcheck="false" tabindex="0">img</code> tag for the provided resource.</li><li><code class="code codeInline" spellcheck="false" tabindex="0">wrap()</code> places HTML tags around content.</li></ul><h2 data-id="safety-tips">Safety tips</h2><ul><li>Use the <code class="code codeInline" spellcheck="false" tabindex="0">Form</code> object to generate HTML forms.</li><li>Use the <code class="code codeInline" spellcheck="false" tabindex="0">Format</code> object to handle outputting user-generated content.</li><li>Use <code class="code codeInline" spellcheck="false" tabindex="0">safeHeader()</code> to send a header.</li><li>Use <code class="code codeInline" spellcheck="false" tabindex="0">safeRedirect()</code> to redirect a user.</li><li>Use <code class="code codeInline" spellcheck="false" tabindex="0">checkPermission()</code> to do just what it says on the tin.</li></ul><h2 data-id="forum-assets">Forum assets</h2><p>See <code class="code codeInline" spellcheck="false" tabindex="0">functions.render.php</code> for more info.</p><ul><li><code class="code codeInline" spellcheck="false" tabindex="0">userUrl()</code> & <code class="code codeInline" spellcheck="false" tabindex="0">userAnchor()</code> take a user and create a URL or full anchor tag around their username.</li><li><code class="code codeInline" spellcheck="false" tabindex="0">userPhoto()</code> & <code class="code codeInline" spellcheck="false" tabindex="0">userPhotoUrl()</code> create a user’s avatar or avatar location, respectively.</li><li><code class="code codeInline" spellcheck="false" tabindex="0">categoryUrl()</code> generates a category’s URL.</li></ul><h2 data-id="developer-tools">Developer tools</h2><ul><li><code class="code codeInline" spellcheck="false" tabindex="0">decho()</code> outputs nicely-formatted debug information nicer than <code class="code codeInline" spellcheck="false" tabindex="0">print_r()</code>.</li><li><code class="code codeInline" spellcheck="false" tabindex="0">deprecated()</code> indicates information about when a method or function was deprecated.</li></ul><p><br></p> </article> </main>