The window.hyva object
When a Hyvä theme is active, the window.hyva JavaScript object provides several helper functions available on every page.
These functions are primarily defined in vendor/hyva-themes/magento2-theme-module/src/view/frontend/templates/page/js/hyva.phtml.
hyva.getCookie(name)
Retrieves the value of a specified cookie.
hyva.setCookie(name, value, days, skipSetDomain)
Sets a cookie. The name and value arguments are required. days and skipSetDomain are optional.
The skipSetDomain argument prevents setting the cookie's domain. Magento's backend behavior is inconsistent, sometimes not setting the domain (e.g., for `mage-messages` in `Magento\Theme\Controller\Result\MessagePlugin::setCookie`). Setting a cookie without `skipSetDomain` to `true` in such cases can result in duplicate cookies.
Cookie consent
By default, cookies are only saved after the visitor has given consent.
To force a cookie to be stored regardless of consent, add its name to the window.cookie_consent_groups.necessary array.
hyva.setSessionCookie(name, value, skipSetDomain)
Available since Hyvä 1.2.9 and 1.3.5
Sets a session cookie. The name and value arguments are required; skipSetDomain is optional.
This method is identical to hyva.setCookie, but the cookie has no expiry and will be deleted when all browser windows or tabs for the site are closed.
hyva.getBrowserStorage()
Returns the native localStorage if available, otherwise falls back to sessionStorage.
If neither is available (common in iOS Safari private mode), a warning is logged to the console, and false is returned.
Example usage:
const browserStorage = hyva.getBrowserStorage();
if (browserStorage) {
const private_content_expire_key = 'mage-cache-timeout';
const cacheTimeout = browserStorage.getItem(private_content_expire_key);
browserStorage.removeItem(private_content_expire_key);
browserStorage.setItem(private_content_expire_key, 3600);
}
hyva.postForm(postParams)
Creates a hidden `