---
title: Environment, session and context
weight: 8
---
`@env`, `@production`, `@session` and `@context` read values only the host application knows.
```html
@production <script src="/analytics.js"></script> @endproduction
@env('local', 'review-*') <div class="debug-bar"></div> @else <!-- live --> @endenv
@session('status') <p class="flash">{{ value }}</p> @endsession
@context('trace') <meta name="trace" content="{{ value }}"> @endcontext
```
- `@env` takes names, lists of names, or several arguments, and `*` matches any run of characters, as in Laravel's `environment()`. `@production` is `@env('production')`. Both accept `@else` and `@elseif`. Standalone, the environment is `Config::environment()`, set with `ConfigBuilder::environment`, read from `SWORD_ENVIRONMENT` by `Config::from_env()`, and `production` by default; a name is 1 to 64 letters, digits, `_`, `-` or `.`. With the `laravel` feature the application's `APP_ENV` is used and the setting is ignored.
- `@session('key')` and `@context('key')` run their body only when the key exists and is not null, with `value` bound to it (escaped when printed). Nested blocks restore the outer `value` afterwards, so a template's own variable named `value` is hidden inside them. `@else` is not supported inside them.
- `@vite('resources/js/app.js')`, `@vite([...])` and `@viteReactRefresh` print the framework's asset tags as trusted markup: from the Vite dev server while `public/hot` exists (with the framework's reload script in debug mode), otherwise from `public/build/manifest.json`. The framework's helper takes only entries, so a build-directory argument is a syntax error, and there is no standalone Vite integration (a render error).
Session and context work only with the Laravel adapter, which reads the request's session and the framework context. A route outside the `web` group has no session, which is a render error that says so. The standalone engine has neither, and `@session` or `@context` there is a render error; pass flash data as view data instead. The key is read at render time and any session key can be read, so only trusted template authors should write these directives.