LemonStand Documentation

Using partials instead of flash messages

Each AJAX call in LemonStand can accept the flash_partial POST parameter, which determines which partial LemonStand should render when the request completes. If this parameter is presented, flash_message() function renders a partial instead if displaying the standard flash message. You can use this feature for displaying formatted messages in response of visitor's actions. For example, the "The product has been added to the cart" message could output a link to the cart page.

Example of the Add to Cart button:

<input onclick="return $(this).getForm().sendRequest('shop:on_addToCart', {
extraFields: {
  flash_partial: 'add_to_cart_partial'
},
update: {'mini_cart': 'shop:mini_cart', 'product_page': 'product_partial'}})"
type="button" value="Add to cart"/>

The add_to_cart_partial partial should exist and should contain a HTML-formatted message to be displayed. Partial example:

<p>The product has been added to the <a href="/cart">cart</a>.</p>

Inside partials rendered using the flash_partial feature, you can access the original flash message text using the $message variable:

<p><?= h($message) ?></p>
<p>Proceed to the <a href="/cart">cart</a>.</p>
<p>{{ message }}</p>
<p>Proceed to the <a href="/cart">cart</a>.</p>

Next: Implementing the "Ship to the billing address" checkbox on the checkout page
Previous: Automatic customer registration
Return to Tips and Tricks