CoolCMS API

InitTrait

Table of Contents

Methods

activeThemeName()  : string|null
Directory name of the currently displayed template (`template1`), or null.
switchableThemes()  : array<int, array{name: string, label: string, description: ?string, active: bool, variants: list, previewColors: list}>
Returns the offer for rendering; an empty array means "render nothing".
switchableVariants()  : array<int, array{skin: ?string, label: ?string, color: ?string, url: string, active: bool}>
Returns catalog variants completed with a link and an "is active" flag.
switchUrl()  : string
Returns the link that switches to the given template and skin: the current URL plus `?_theme=...&_skin=...`.

Methods

activeThemeName()

Directory name of the currently displayed template (`template1`), or null.

private activeThemeName() : string|null
Return values
string|null

switchableThemes()

Returns the offer for rendering; an empty array means "render nothing".

private switchableThemes() : array<int, array{name: string, label: string, description: ?string, active: bool, variants: list, previewColors: list}>

The catalog (ThemeCatalog) knows each template and its colors; this trait adds only what belongs to the visitor: switch links and the "currently viewed" flag.

Each template carries a list of variants: color dots that select the template and its skin at once. The first is always the base look (no skin), followed by the template's skins. A template without skins has a single dot.

Return values
array<int, array{name: string, label: string, description: ?string, active: bool, variants: list, previewColors: list}>

switchableVariants()

Returns catalog variants completed with a link and an "is active" flag.

private switchableVariants(string $themeName, array<int, array{skin: ?string, label: ?string, color: ?string, duplicateColor: bool}> $variants) : array<int, array{skin: ?string, label: ?string, color: ?string, url: string, active: bool}>

IMPORTANT: a color the catalog marked as repeated (duplicateColor) is dropped from the offer, because two identical dots side by side look like a bug and a click shows no difference. The exception is the currently active skin: it stays even with a duplicate color, otherwise the check mark would have nothing to attach to and the panel would claim nothing is selected. That is why it is not filtered in the catalog, which does not know what the visitor is viewing.

Parameters
$themeName : string
$variants : array<int, array{skin: ?string, label: ?string, color: ?string, duplicateColor: bool}>
Return values
array<int, array{skin: ?string, label: ?string, color: ?string, url: string, active: bool}>

switchUrl()

Returns the link that switches to the given template and skin: the current URL plus `?_theme=...&_skin=...`.

private switchUrl(string $themeName, string|null $skin) : string

Staying on the same page is intended: the visitor wants to see this content in another look, not jump to the home page. The parameters stay in the address, which is fine on the demo site; a shared link shows the recipient the same thing.

NOTE: the link is not a signal (handle...): that would need a CSRF token and change on every redraw, so it could be neither cached nor shared. Switching is safe: it changes only the cookie of whoever clicked.

IMPORTANT: a choice equal to the site setting sends off, which cancels the choice. Sending the name would store a hard cookie when the visitor clicks the default look, so a later admin change would never reach them while they feel they "switched nothing". This holds for the template and the skin separately. The skin comparison applies only within the target template; for a skin of another template off is not sent even if the name matches.

IMPORTANT: both parameters always go together. A dot selects the pair (template, skin), so a click on the base look must also cancel the skin; otherwise the skin from the previous choice would stay and not belong to the new template.

Parameters
$themeName : string
$skin : string|null
Return values
string
On this page

Search results