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.

Creating a Partial

This page continues the Creating pages with LemonStand article.

Partials are an important component of LemonStand's template engine. Partials enable you to share code blocks among multiple pages. Code reusing allows you to save much time when you develop complicated websites. For example, you can create a partial for rendering a product list and use this partial on the Category page and on the Home page. Instead of writing the same code in each page, you can just ask LemonStand to render the partial.

For learning purposes, let's create a simple partial which will display a current date. Then we will render it on our Hello, World page. Go to the CMS/Partials page and click the Add partial button. Specify the partial name (current_date is a suitable name for our case). Partial description is optional, but we recommend that you specify descriptions for your partials, because it simplifies finding a specific partial in the partial list.

The HTML Code field can contain any HTML or PHP code. Paste the following code in the HTML Code field:

<p>Today is <?= date('F, j') ?></p>
<p>Today is {{ date('F, j') }}</p>

Click the Create and then the Close button. Now you can use the partial you just created. Return to the CMS/Pages page and click the Hello World page. Add the following line to the bottom of the page code: 

<? $this->render_partial('current_date') ?>
{{ render_partial('current_date') }}

The method render_partial of the page controller renders a partial with specified name. Save the page and click the page link above the form. You should see a current date displayed above the page footer. Once you create a partial you can render it on any page of your website.

Next: Using the Page Head Declarations Field
Previous: Adding a Layout
Return to The Page Basics