Blog navigation keyboard_arrow_down

Blog Rss rss_feed

Templates and Layouts in PrestaShop: A Comprehensive Guide to Structure, Examples, and Customization

Templates and Layouts in PrestaShop: A Comprehensive Guide to Structure, Examples, and Customization

PrestaShop is a popular e-commerce platform, offering extensive customization options for online stores. One of the key elements of this platform is its system of templates and layouts, which allows developers to fine-tune the store’s look and functionality. In this article, we’ll break down the structure of templates and layouts in PrestaShop, describe how to organize them properly, and provide examples for clarity.

The Basics of Templates in PrestaShop

Templates in PrestaShop are based on the Smarty 4 template engine, which enables the creation of dynamic pages using HTML and special tags. All template files should be stored in the templates folder within the theme, such as in /themes/classic/templates for the default theme.

Directory Structure of Templates

For easier management and readability, templates are organized into folders, each responsible for a specific part of the site:

  • /partials/ – contains shared elements of the site, such as the header, footer, and notifications.
  • /catalog/ – templates for product pages, categories, brands, search results, etc.
  • /checkout/ – templates for the cart, delivery options, payment options, and order confirmations.
  • /cms/ – templates for static content like contact pages, site maps, CMS pages, and so on.
  • /customer/ – everything related to the customer’s account and information.
  • /errors/ – error templates, such as “not found,” “server error,” and “forbidden” pages.
  • /layouts/ – theme layouts, including one-column, two-column, full-width layouts, and more.

The _partials folder contains template fragments that are used across multiple pages, allowing centralized editing of elements applied to all pages where the fragment is used.

Difference Between Template and Layout

It’s essential to understand the difference between a template and a layout:

  • Layout – the page structure, defining the arrangement of elements (e.g., sidebar presence).
  • Template – specific to a feature, such as the product page.

Key template files include:

  • index.tpl – home page.
  • catalog/product.tpl – product page.
  • catalog/listing/product-list.tpl – product listing page.
  • checkout/cart.tpl – cart page.
  • checkout/checkout.tpl – checkout process page.

Specific Templates

If your store targets multiple languages or regions, unique templates can be created for specific countries or languages. For example, if you need different page designs for American and Japanese customers, create a product.tpl template for each language and place it in the corresponding folder.

When loading a template, PrestaShop checks multiple locations to find the appropriate file. This makes it easy to create unique templates for different locales or specific categories. For example, for a product page with ID=3 and locale en-US, the following files are checked in this order:

  1. en-US/catalog/product-3.tpl
  2. catalog/product-3.tpl
  3. en-US/catalog/product.tpl
  4. catalog/product.tpl

Example of a Category Page Template

For a category page with ID=9 and locale en-US, the following files are checked in this order:

  1. en-US/catalog/listing/category-9.tpl
  2. catalog/listing/category-9.tpl
  3. en-US/catalog/listing/category.tpl
  4. catalog/listing/category.tpl
  5. en-US/catalog/listing/product-list.tpl
  6. catalog/listing/product-list.tpl

This feature is particularly useful for developers working on custom templates for clients with specific requirements.

Layouts in PrestaShop

A layout defines the page’s organization, such as whether a sidebar is present or if the product listing takes up the entire space. PrestaShop users can change the layout of each page independently, and as a developer, your role is to ensure that your theme is compatible.

Example of a Layout File

A layout sits at the top of the template hierarchy, responsible for structuring and including different blocks. A typical layout file might look like this:

<!doctype html> <html lang="{$language.iso_code}"> <head> {block name='head'} {include file='_partials/head.tpl'} {/block} </head> <body id="{$page.page_name}" class="{$page.body_classes|classnames}"> {hook h='displayAfterBodyOpeningTag'} <main> <header id="header"> {block name='header'} {include file='_partials/header.tpl'} {/block} </header> <section id="wrapper"> <div class="container"> {block name='breadcrumb'} {include file='_partials/breadcrumb.tpl'} {/block} {block name="left_column"} <div id="left-column"> {if $page.page_name == 'product'} {hook h='displayLeftColumnProduct'} {else} {hook h="displayLeftColumn"} {/if} </div> {/block} {block name="content_wrapper"} <div id="content-wrapper"> {block name="content"} <p>Welcome! This is HTML5 Boilerplate.</p> {/block} </div> {/block} </div> </section> <footer id="footer"> {block name="footer"} {include file="_partials/footer.tpl"} {/block} </footer> </main> {hook h='displayBeforeBodyClosingTag'} {block name='javascript_bottom'} {include file="_partials/javascript.tpl" javascript=$javascript.bottom} {/block} </body> </html>

Templates and layouts in PrestaShop provide extensive customization options, making the store’s interface more flexible and dynamic. The well-thought-out file structure enables quick adjustments to the design and functionality. If you want to create a unique look for your online store or tailor it to specific requirements, PrestaShop’s template and layout system is your go-to tool.

Share your thoughts on PrestaShop templates and structure in the comments!

Was this blog post helpful to you?

    
No comments at this moment
close

Checkout

close

Favourites