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
| Variable | Type | Description |
|---|---|---|
mw.lang | string | Current language (ru, en, etc.) |
mw.path | string | Base application path |
mw.csrf | string | CSRF token for forms |
mw.user | object|null | Currently authenticated user (or null for guests) |
mw.config | object | Project configuration |
mw.projectName | string | Project name |
mw.navigation | array | Navigation menu |
mw.game | object | Game settings and data |
mw.version | string | MMO-DEV WEB platform version |
mw.time | int | Current Unix timestamp |
mw.isDebug | bool | Whether debug mode is enabled |
mw.isDevelopment | bool | Development 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:
| Variable | Type | Description |
|---|---|---|
mw.request.host | string | Host (example.com) |
mw.request.uri | string | Full URI (/page?key=value) |
mw.request.path | string | Path without query string (/page) |
mw.request.method | string | HTTP method (GET, POST) |
mw.request.scheme | string | Scheme (http or https) |
mw.request.schemeAndHttpHost | string | Full host (https://example.com) |
mw.request.queryString | string | Query string (key=value&foo=bar) |
mw.request.isSecure | bool | HTTPS connection |
mw.request.isXmlHttpRequest | bool | AJAX 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
| Variable | Description |
|---|---|
_self | Name of the current template |
_context | All variables in the current context (useful for dump()) |
_charset | Current 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
| Variable | Type | Description |
|---|---|---|
is_guest | bool | Whether the visitor is a guest |
active_page | string | Current page identifier |
notifications | array | User notifications |
balance | float | User balance |
Servers
| Variable | Type | Description |
|---|---|---|
servers | array | List of game servers |
current_server | object | Currently 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 %}