Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

Taking your approach on designing things actually makes it fun, more natural, and overall easier.

— Dominik, Developer

Session:Set Tag

Data set in the session will be available in all future requests until such time that the session is cleared over time (sessions eventually expire) or intentionally. Session variables can be retrieved with the main session tag.

Example

This can be used for many different things. For example, you could set a variable on the form success page if a user has filled out a special survey form.

{{ session:set entered_survey="true" }}
{{-- Using Antlers Blade Components --}}
<s:session:set entered_survey="true" />
 
{{-- Using session() helper --}}
@php(session()->put('entered_survey', true))

Later you could decide to show a message instead of the form if the user has already filled it out.

{{ session }}
{{ if entered_survey }}
<p>You already filled out the form.</p>
{{ /if }}
{{ /session }}
@if (session()->get('entered_survey'))
<p>You already filled out the form.</p>
@endif

Multiple Variables

You can set multiple variables at once and reference interpolated data (references to variables).

{{ session:set likes="hats" :visited="url" }}
{{-- Using Antlers Blade Components --}}
<s:session:set likes="hats" :visited="url" />

Tag Pair

This tag is also available as a pair, which can be used to immediately display set data.

{{ session:set likes="boomboxes" }}
<p>You like {{ likes }}, huh?</p>
{{ /session:set }}
<s:session:set likes="boomboxes">
<p>You like {{ $likes }}, huh?</p>
</s:session:set>

Setting Array Data

Array data can be set with dot notation.

{{ session:set likes.books="true" likes.hats="true" }}
{{-- Using Antlers Blade Components --}}
<s:session:set likes.books="true" likes.hats="true" />

Forgetting Data

Data can be removed from the session session:forget, and the entire session flushed with session:flush. 🚽

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →