---
title: Global Variables
---

# Global Variables

<div class="documentation__toc"></div>

## Introduction

Currently there is only the `template` global variable. Often times active entries (like a currently viewed page or post) are available on the `template` variable for use elsewhere in the templating structure.

```twig
{% if template.post.id %}
    <h1>{{ post.title }}</h1>
{% endif %}
```

### Setting Values

You can set your own template variables for access anywhere by using the `\Anomaly\Streams\Platform\View\ViewTemplate` within your PHP code:

```php
$template = app(\Anomaly\Streams\Platform\View\ViewTemplate::class);

$template->set('meta_title', $page->getTitle());
```

You can also do this within views themselves. This can be helpful when content and layout are rendered separately and one (content) is injected into the other (layout) secretly.

```twig
{% do template.set('meta_title', page.title.value) %}
```
