class Theme implements ExtenderInterface

Methods

overrideLessImport(string $file, string $newFilePath, string $extensionId = null)

<p>This can be used to override LESS files that are imported within the code.</p>

overrideFileSource(string $file, string $newFilePath, string $extensionId = null)

<p>This method allows overriding LESS file sources.</p>

addCustomLessFunction(string $functionName, callable $callable)

<p>This method allows you to add custom Less functions.</p>

addCustomLessVariable(string $variableName, callable $value)

<p>Defines a new Less variable to be accessible in all Less files.</p>

extend(Container $container, Extension $extension = null)

No description

Details

Theme overrideLessImport(string $file, string $newFilePath, string $extensionId = null)

<p>This can be used to override LESS files that are imported within the code.</p>

<p>For example, core's <code>forum.less</code> file imports a <code>forum/DiscussionListItem.less</code> file. The contents of this file can be overriden with this method.</p>

Parameters

string $file <p>: Relative path of the file to override, for example: <code>forum/Hero.less</code></p>
string $newFilePath <p>: Absolute path of the new file.</p>
string $extensionId <p>: If overriding an extension file, specify its ID, for example: <code>flarum-tags</code>.</p>

Return Value

Theme

Theme overrideFileSource(string $file, string $newFilePath, string $extensionId = null)

<p>This method allows overriding LESS file sources.</p>

<p>For example <code>forum.less</code>, <code>admin.less</code>, <code>mixins.less</code> and <code>variables.less</code> are file sources, and can therefore be overriden using this method.</p>

Parameters

string $file <p>: Name of the file to override, for example: <code>admin.less</code></p>
string $newFilePath <p>: Absolute path of the new file.</p>
string $extensionId <p>: If overriding an extension file, specify its ID, for example: <code>flarum-tags</code>.</p>

Return Value

Theme

Theme addCustomLessFunction(string $functionName, callable $callable)

<p>This method allows you to add custom Less functions.</p>

<p>All custom Less functions may only return numbers, strings or booleans.</p> <p><strong>Example usage:</strong></p> <pre><code class="language-php">(new Extend\Theme) -&gt;addCustomLessFunction('is-flarum', function (mixed $text) { return strtolower($text) === 'flarum' }),</code></pre>

Parameters

string $functionName <p>Name of the function identifier.</p>
callable $callable <p>The PHP function to run when the Less function is called.</p>

Return Value

Theme

See also

https://leafo.net/lessphp/docs/#custom_functions

Theme addCustomLessVariable(string $variableName, callable $value)

<p>Defines a new Less variable to be accessible in all Less files.</p>

<p>If you want to expose a setting from your database to Less, you should use the <code>registerLessConfigVar</code> extender from <code>Extend\Settings</code> instead.</p> <p>Please note the value returned from the callable will be inserted directly into the Less source. If it is unsafe in some way (e.g., contains a semi-colon), this will result in potential security issues with your stylesheet.</p> <p>Likewise, if you need your variable to be a string, you should surround it with quotes yourself.</p> <pre><code class="language-php">(new Extend\Theme()) -&gt;addCustomLessVariable('my-extension__asset_path', function () { $url = resolve(UrlGenerator::class); $assetUrl = $url-&gt;to('forum')-&gt;base().'/assets/extensions/my-extension/my-asset.jpg'; return "\"$assetUrl\""; })</code></pre>

Parameters

string $variableName <p>Name of the variable identifier.</p>
callable $value <p>The PHP function to run, which returns the value for the variable.</p>

Return Value

Theme

extend(Container $container, Extension $extension = null)

Parameters

Container $container
Extension $extension