After - Liquid Tag Reference
On this page
The after block tag runs its content after the main page template has rendered. Use it in a Liquid controller to send custom responses or redirects based on what happened during rendering.
:::note
This tag works only inside a Liquid controller template (at controllers/<controller>/<action>.liquid). It is a silent no-op outside a controller.
:::
When after runs
In a Liquid controller, execution flows through three phases:
{% before %}block — runs first- Standard action — the main controller logic
- Page rendering — the template output
{% after %}block — runs after rendering ← you are here{% final %}block — runs after response sent
Syntax
```liquid
{% after %} {% redirect to: current_store.cart_path %} {% endafter %} ```
| Property | Value |
|---|---|
| Tag Name | after |
| Type | Block tag |
| Source | StoreConnect |
What’s available in after
- Page has rendered — the main template output is complete
current_request.params— still accessible- All globals —
current_store,current_customer,current_cart, etc. - All tags —
{% respond %},{% redirect %}, but NOT{% action %}(actions are for before/standard action)
Common tasks in after
1. Redirect after successful action
```liquid
{% before %} {% action “cart.add”, product_identifier: current_product.id, quantity: 1 %} {% endbefore %}
{% after %} {% redirect to: current_store.cart_path, notice: “Item added to cart” %} {% endafter %} ```
2. Send a custom JSON response
```liquid
{% before %} {% params quantity: current_request.params.quantity %} {% endbefore %}
{% after %} {%- new Map result -%} {%- assign result = result | set_key: “success”, true -%} {%- assign result = result | set_key: “cart_count”, current_cart.items.size -%} {% respond body: result | json, status: 200, layout: false %} {% endafter %} ```
3. Conditional redirect
```liquid
{% before %} {% params product_id: current_request.params.id %} {% endbefore %}
{% after %} {% if current_cart.items.size > 10 %} {% redirect to: current_store.cart_path, alert: “Cart is getting full” %} {% else %} {% redirect to: current_product_path %} {% endif %} {% endafter %} ```
Key behaviors
- Runs after page renders — the template output is complete, but not yet sent to the client
- Can send responses — override the page output with a custom response (JSON, redirect, etc.)
- Can redirect — stops output and sends the client to a new URL
- Cannot undo rendering — the page output has already been calculated;
{% respond %}and{% redirect %}replace it {% respond %}skips{% final %}— but{% redirect %}does not; final still runs
Redirect with flash message
A common pattern is to redirect with a flash message (notice or alert) set by the user.
```liquid
{% after %} {% redirect to: current_store.account_path, notice: “Profile updated successfully” %} {% endafter %} ```
The notice appears on the target page (usually a page.liquid that renders flash messages).
Related phases
{% before %}— runs before rendering; use for validation and actions{% final %}— runs after response sent; use for fire-and-forget work- See Liquid controller lifecycle for the complete flow
Was this article helpful?
Thanks for your feedback! It helps us improve our docs.