Skip to main content

MMO-DEV WEB Global Variables

Every MMO-DEV WEB template has access to global variables through the mw object and built-in Twig variables.

The mw Object​

Main Properties​

VariableTypeDescription
mw.langstringCurrent language (ru, en, etc.)
mw.pathstringBase application path
mw.csrfstringCSRF token for forms
mw.userobject|nullCurrently authenticated user (or null for guests)
mw.configobjectProject configuration
mw.projectNamestringProject name
mw.navigationarrayNavigation menu
mw.gameobjectGame settings and data
mw.versionstringMMO-DEV WEB platform version
mw.timeintCurrent Unix timestamp
mw.isDebugboolWhether debug mode is enabled
mw.isDevelopmentboolDevelopment environment

Usage Examples​

Usage Examples
{# Language #}
<html lang="{{ mw.lang }}">

{# CSRF token in forms #}
<form method="post">
<input type="hidden" name="_token" value="{{ mw.csrf }}">
</form>

{# Authentication check #}
{% if mw.user %}
Hello, {{ mw.user.name }}!
{% else %}
<a href="/login">Log in</a>
{% endif %}

{# Configuration #}
{{ mw.projectName }}
{{ mw.config.siteName }}

{# Debugging #}
{% if mw.isDebug %}
{{ dump(_context) }}
{% endif %}

The mw.request Object​

Information about the current HTTP request:

VariableTypeDescription
mw.request.hoststringHost (example.com)
mw.request.uristringFull URI (/page?key=value)
mw.request.pathstringPath without query string (/page)
mw.request.methodstringHTTP method (GET, POST)
mw.request.schemestringScheme (http or https)
mw.request.schemeAndHttpHoststringFull host (https://example.com)
mw.request.queryStringstringQuery string (key=value&foo=bar)
mw.request.isSecureboolHTTPS connection
mw.request.isXmlHttpRequestboolAJAX request

Examples​

Examples
{# Current URL #}
{{ mw.request.schemeAndHttpHost }}{{ mw.request.uri }}

{# Active navigation #}
<a href="/news" class="{{ mw.request.path starts with '/news' ? 'active' : '' }}">
News
</a>

{# Detecting AJAX #}
{% if mw.request.isXmlHttpRequest %}
{# Render without layout #}
{{ content }}
{% else %}
{% extends '@site/layout.html.twig' %}
{% endif %}

Built-in Twig Variables​

VariableDescription
_selfName of the current template
_contextAll variables in the current context (useful for dump())
_charsetCurrent charset (usually UTF-8)
Built-in Twig Variables
{# View all variables #}
{{ dump(_context|keys) }}

{# Current template name #}
<!-- Template: {{ _self }} -->

Context Variables​

These variables are available depending on the controller and page:

General​

VariableTypeDescription
is_guestboolWhether the visitor is a guest
active_pagestringCurrent page identifier
notificationsarrayUser notifications
balancefloatUser balance

Servers​

VariableTypeDescription
serversarrayList of game servers
current_serverobjectCurrently selected server

Examples​

Examples
{# Guest content #}
{% if is_guest %}
<div class="guest-banner">
Register to get access to all features!
</div>
{% endif %}

{# Notifications #}
{% if notifications is defined and notifications is not empty %}
<div class="notifications">
{% for notification in notifications %}
<div class="alert alert-{{ notification.type }}">
{{ notification.message }}
</div>
{% endfor %}
</div>
{% endif %}

{# Servers #}
{% for server in servers %}
<div class="server {{ server == current_server ? 'active' : '' }}">
{{ server.name }} - {{ server.online }} online
</div>
{% endfor %}

{# Balance #}
{% if balance is defined %}
Balance: {{ balance|number_format(2, '.', ',') }}
{% endif %}