Skip to content
Log in

Accounts Controller - Liquid Controller Reference

On this page

Description

Use Liquid controller templates in controllers/accounts/ to intercept account requests before or after they are processed — for example, to redirect users, set template variables, or write custom Contact fields during registration.

Property Value
Controller AccountsController
Liquid Template Path controllers/accounts/

Actions

Action HTTP Method Route Liquid Page Description
show GET /accounts/:id account Renders the account page for the current customer.
register GET /accounts/register Renders the registration form.
create POST /accounts Processes the registration form submission and creates the Account and Contact.
missing_details GET /accounts/missing-details Shown when a customer logs in but required account fields are incomplete.
go_back_with_errors GET /accounts/go-back-with-errors Redirects the customer back to the previous form with validation errors surfaced.

Liquid Controller Lifecycle

For each action, Liquid controller templates are executed in three phases:

  1. Beforecontrollers/accounts/{action}.liquid runs before the Rails action
  2. After — runs after the Rails action but before the response is sent
  3. Final — runs after the response is sent; use it to clean up session variables or temporary state

Available Liquid Tags

Inside controller templates, these tags are available:

Tag Description
{% params %} Set request parameters (e.g. {% params foo: "bar" %})
{% variables %} Set template variables (e.g. {% variables title: "Hello" %})
{% respond %} Respond with custom content, alert, or notice
{% redirect %} Redirect the request (e.g. {% redirect to: "/products" %})
{% action %} Execute a server-side action (e.g. {% action "cart.add" %})

Example: basic show customization

Create a file at controllers/accounts/show.liquid:

```liquid

{% before %} variables custom_heading: “Welcome” {% endbefore %} ```

Custom fields during registration

The create action runs when a visitor submits the registration form. You can use the before and after phases to pass custom fields from the registration form directly to the new Contact record, without needing a separate generic form.

StoreConnect creates the Account and Contact on the website side and then syncs the changes to Salesforce automatically — including any custom field values you write in the after phase.

How it works

Phase Purpose
before Check for an existing Contact with the same email and store the result in session — this blocks duplicate registrations
after Find the newly created Contact and write custom field values from the form params
final Clear the session variable used during duplicate checking

Example: adding a birthdate field

This example: - Blocks registration if a Contact with the same username (email) already exists - Writes a birthdate field from the form to the new Contact after creation

Create a file at controllers/accounts/create.liquid:

```liquid

{% liquid before session registration_contact_id: blank

assign username = current_request.params.email

if username != blank and username != nil
  query 'Contact' as contacts, s_c__username__c: username
  if contacts.size > 0
    assign contact = contacts | first
    session registration_contact_id: contact.s_c__sc_id__c
  endif
endif   endbefore

after new Map additional_fields_map assign additional_fields_map = additional_fields_map | set_key: ‘birthdate’, ‘birthdate’

assign params = current_request.params
assign username = current_request.params.email

if username != blank and username != nil
  if session_variables.registration_contact_id == blank
    query 'Contact' as contacts, s_c__username__c: username
    if contacts.size > 0
      assign contact = contacts | first
      assign contact_drop = contact | cast: 'Contact'
      assign additional_fields = additional_fields_map | keys
      for field in additional_fields
        if params contains field
          assign sf_field = additional_fields_map[field]
          assign value = current_request.params[field]
          update contact_drop, field: sf_field, value: value
        endif
      endfor
    endif
  endif
endif   endafter

final session registration_contact_id: blank endfinal %} ```

Adding more custom fields

To write additional fields, add more set_key calls to additional_fields_map in the after phase. The key is the name attribute of the form input; the value is the Salesforce field API name on the Contact object.

```liquid

assign additional_fields_map = additional_fields_map | set_key: ‘birthdate’, ‘birthdate’ assign additional_fields_map = additional_fields_map | set_key: ‘phone’, ‘phone’ assign additional_fields_map = additional_fields_map | set_key: ‘company_name’, ‘custom_company_name__c’ ```

Each key must match the name attribute of the corresponding input in your registration form template.

:::note The duplicate-contact check in the before phase uses s_c__username__c, which StoreConnect stores as the contact’s email address. If a Contact with that username already exists, registration_contact_id is set in session and the after phase skips the field update — the registration form will surface an error to the visitor. :::

Was this article helpful?

Was this article helpful?