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.

Managing Page Navigation and Hierarchy

LemonStand includes features for generating site maps and dynamic menus. Using these features you can display a whole site map or only subpages of a specific page. Displaying site maps and menus involves partials. It gives you unlimited power in customizing the markup and content of your website navigation.

We will demonstrate the navigation building features with simple tutorials.

Managing the page hierarchy and page navigation visibility

Pages in LemonStand can be grouped, forming a page tree. The page hierarchy is taken into account only during the site maps or dynamic menu generation. The page hierarchy does not affect page URLs.

You can manage page navigation behavior on the Navigation tab of the Create/Edit Page page. On this page you can select a page parent, specify whether the page should be visible in automatically generated menus and specify the page menu label. 

By default pages in the site map and other menus are sorted in the order creation time. You can manage page order manually. Click the Manage page order button on the CMS/Pages page to open the order management tool. On this page you can drag pages up and down using the page icons as handles.

Displaying nested pages

You can notice that the site map does not display nested pages. In order to display nested pages we need to extend the partial, making it render itself or each page, in case the page has subpages. This method is called recursion in programming.

<? foreach ($pages as $page): ?>
	<li>
		<a href="<?= $page->url ?>"><?= h($page->navigation_label()) ?></a>
		<? 
			$subpages = $page->navigation_subpages(); 
			if ($subpages):
		?>
			<ul>
				<?= $this->render_partial('sitemap_pages', array('pages'=>$subpages)) ?>
			</ul>
		<? endif ?>	

	</li>	
<? endforeach ?>
{% for page in pages %}
	<li>
		<a href="{{ page.url }}">{{ page.navigation_label }}</a>
		{% set subpages = page.navigation_subpages() %}
		{% if subpages %}
			<ul>
				{{ render_partial('sitemap_pages', {'pages': subpages}) }}
			</ul>
		{% endif %}
	</li>	
{% endfor %}

The code loads a list of subpages of each page: 

$subpages = $page->navigation_subpages(); 
set subpages = page.navigation_subpages()

Then checks whether subpages exist, and if so, outputs the UL element and then renders the partial again, passing the list of subpages to it. If you refresh the site map page, you will see that now it contains subpages.

 

Displaying subpages of a specific page

Similarly to the method described above, you can output subpages of a specific page, instead of displaying a full website map. Let's suppose you have the About page with the '/about' URL, and this page has subpages. We want to output the subpages of the About page.

<?
	$about_page = Cms_Page::create()->find_by_url('/about');
	$this->render_partial('sitemap_pages', array('pages'=>$about_page->navigation_subpages())) 
?>
{% set about_page = method('Cms_Page', 'create').find_by_url('/about') %}
{{ render_partial('sitemap_pages', {'pages': about_page.navigation_subpages()}) }}

You can use this code in a page, where you want to output a list of the About page subpages. The code loads the About page. Then it renders the partial which we created in the site map tutorial. But instead of passing a list of root pages to the partial, we now passing the subpages of the About page.

Next: Using Twig Templating Engine
Previous: Page Not Found (404) page
Return to LemonStand Back-End