This is the documentation for LemonStand V1, which has been discontinued. You can learn more and upgrade your store here.

LemonStand Version 1 Has Been Discontinued

This documentation is for LemonStand Version 1. LemonStand is now offered as a cloud-based eCommerce platform.
You can try the new LemonStand and learn about upgrading here.

Using Twig Templating Engine

LemonStand supports two templating engines - PHP and Twig. You can choose a templating engine for each theme individually on the Create/Edit Theme page:

If theming is disabled in your LemonStand installation, you can choose the templating engine in the CMS Settings form:

You can download free Basic theme written with Twig from the Marketplace: https://lemonstandapp.com/marketplace/theme/basic-twig/

Twig syntax

You can learn Twig syntax by reading the official Twig documentation: http://twig.sensiolabs.org/. Twig syntax example:

{{
  render_partial(
    'shop:product_list', 
    {
      'products': category.list_products({'sorting': sorting_preferences}),
      'records_per_page': 6,
      'paginate': true, 
      'pagination_base_url': category.page_url('category'),
      'page_index': request_param(1, 0)
    }
  ) 
}}

Most of the functions available in PHP themes are available in Twig themes as well. However a few Twig-specific function has been added. You can find the full list of Twig-specific function in the Reference.

In Twig templates you should use this variable instead of $this to access the controller's methods and properties. For example:

{% if not this.customer %}
  Welcome, guest!
{% endif %}

Accessing virtual object properties

In most cases you can access objects fields and methods directly:

{# Output cart item product name #}
Product name: {{ item.product.name }}

{# Load the options string from cart item #}
{% set options_str = item.options_str() %}

However, Twig cannot access virtual class fields directly. This line would trigger "method doesn't exist error", because name is a virtual field of the Shop_Customer class, implemented with the __get() method:

{{ this.customer.name }}

You can access such fields with the field Twig function:

{{ field(this.customer, 'name') }}

The rule of thumb: if you are sure that an object property does exist, but Twig says that the method doesn't exist, use the field() function. If you use proxy models, you should always use the field() function to access proxiable fields.

Invoking static class methods

Static class methods should be invoked using the method() function:

{% set active_items = method('Shop_Cart', 'list_active_items') %}

Accessing controller methods with functions

Although you can access any controller method with the this variable, some controller methods are also available as functions, which makes templates syntax less verbose. For example, instead of this line

{{ this.render_partial('shop:cart_table') }}
you can write this:

{{ render_partial('shop:cart_table') }}

Full list of controller methods available as functions

  • render_partial()
  • js_combine()
  • css_combine()
  • render_page()
  • render_block()
  • render_head()
  • request_param()

PHP code in Twig themes

You can use PHP code in Twig themes in pages' Pre Action Code, Post Action Code and AJAX Handlers field. However PHP is not supported in lower tiered SaaS accounts due to security considerations. Pre Action Code, Post Action Code and AJAX Handlers fields are not available when PHP features are disabled.

Next: Generating Site Maps
Previous: Managing Page Navigation and Hierarchy
Return to LemonStand Back-End