prestashop template and theme development

PrestaShop 1.7 Template Development: A Developer’s Blueprint

No Comments

Kristian Ole Rørbye

By Kristian Ole Rørbye

Creating a custom template for PrestaShop 1.7 can be a rewarding yet challenging experience. A well-designed template enhances the visual appeal of an online store and improves user experience and conversion rates. This article aims to guide you through the entire process of building a custom template, from the initial planning stages to the final steps of packaging and distribution.

Whether you’re a seasoned PrestaShop developer or a newcomer eager to learn, this guide offers a structured approach to theme development. We’ll cover everything from setting up your development environment and understanding PrestaShop’s default theme structure to advanced topics like working with the Smarty template engine and creating custom modules.

Chapter 1: Preliminary Steps

Contents show

1.1 Setting Up a Development Environment

Before diving into the actual development, setting up a local development environment is crucial. This isolated setup allows you to experiment and make changes without affecting a live website. You can use software like XAMPP, WAMP, or Docker to create a local server that mimics a live hosting environment.

Steps to Set Up a Local Environment:

  1. Download and install your preferred local server software.
  2. Create a new database for your PrestaShop installation.
  3. Configure PHP settings as per PrestaShop’s requirements.

1.2 Installing PrestaShop 1.7

Once your local environment is ready, the next step is to install PrestaShop 1.7. You can download the latest version from the official PrestaShop website. Follow the installation guide to set up the software on your local server.

Installation Steps:

  1. Download the PrestaShop 1.7 package.
  2. Extract the package into your local server’s root directory.
  3. Navigate to the installation URL and follow the on-screen instructions.

1.3 Understanding the Default Theme Structure

PrestaShop 1.7 comes with a default theme called “Classic,” which serves as a good starting point for understanding the file structure and organization of PrestaShop themes. Spend some time exploring the directories and files to get a sense of how things are laid out.

Key Directories and Files:

  • /themes/classic/templates: Contains Smarty template files.
  • /themes/classic/assets: Holds CSS, JavaScript, and image files.
  • /themes/classic/config: Includes the theme.yml configuration file.

1.4 Tools and Software Requirements

Before proceeding, make sure you have the essential tools for theme development. These typically include a code editor (like Visual Studio Code or Sublime Text), version control software (such as Git), and debugging tools.

Recommended Tools:

  • Code Editor: Visual Studio Code, Sublime Text
  • Version Control: Git
  • Debugging: Xdebug, browser developer tools

By completing these preliminary steps, you’ll have a solid foundation to start developing your custom PrestaShop 1.7 template. In the next chapter, we’ll delve into the planning phase, where you’ll sketch out your template’s design and functionality.

Chapter 2: Planning Your Template

2.1 Defining the Scope

Before you start coding, it’s essential to define the scope of your template. What kind of online store is it going to serve? Will it be a general-purpose template or tailored for a specific industry like fashion, electronics, or food?

Key Considerations:

  • Target audience
  • Required features
  • Budget and timeline

2.2 Sketching the Layout

Once you have a clear understanding of the scope, the next step is to sketch the layout of your template. You can use wireframing tools or even pen and paper to outline the basic structure.

Layout Components:

  • Header
  • Footer
  • Sidebar
  • Product grid
  • Checkout page

2.3 Identifying Required Features and Modules

Based on your scope and layout, identify the features and modules you’ll need. This could include things like a carousel for featured products, a quick view option, or a custom search bar.

Common Features:

  • Product carousel
  • Quick view
  • Custom search bar
  • Social media integration

2.4 Planning for Responsiveness

In today’s digital landscape, responsiveness is a must. Plan how your template will adapt to various screen sizes, from mobile devices to large desktop monitors.

Responsive Design Considerations:

  • Mobile-first approach
  • CSS media queries
  • Testing on multiple devices

By the end of this planning phase, you should have a well-defined blueprint for your custom template. This will serve as your roadmap throughout the development process, helping to keep your project on track and aligned with your initial vision.

Chapter 3: File Structure and Organization

3.1 Overview of PrestaShop Theme Architecture

Understanding the architecture of PrestaShop themes is crucial for effective development. PrestaShop 1.7 themes are primarily composed of Smarty templates, SCSS/CSS files, JavaScript, and a configuration file (theme.yml).

Theme Components:

  • Smarty templates
  • SCSS/CSS files
  • JavaScript files
  • Configuration files

3.2 Creating the Theme Folder

Your custom theme will reside in its own folder within the themes directory of your PrestaShop installation. Create a new folder and give it a name that reflects the theme you’re developing.

Steps to Create Theme Folder:

  1. Navigate to /themes/ in your PrestaShop directory.
  2. Create a new folder, e.g., my_custom_theme.

3.3 Required Files and Directories

Every PrestaShop theme requires a specific set of files and directories to function correctly. These include template files, asset folders, and a configuration file.

Required Structure:

  • /templates: For Smarty template files
  • /assets: For CSS, JavaScript, and images
  • /config: For the theme.yml configuration file

3.4 Naming Conventions

Proper naming conventions make your theme easier to maintain and collaborate on. Stick to a consistent naming scheme for your files and folders.

Best Practices:

  • Use lowercase and hyphens for file and folder names (e.g., product-list.tpl).
  • Prefix custom SCSS and JavaScript files to distinguish them from core files (e.g., custom-styles.scss).

By the end of this chapter, you should have a well-organized theme folder with all the required files and directories. This structure will serve as the backbone of your custom template, making it easier to manage as you add more features and styles.

Chapter 4: Theme Configuration

4.1 Creating the theme.yml File

The theme.yml file is the configuration file for your custom theme. It resides in the /config directory within your theme folder and contains essential metadata and settings.

Steps to Create theme.yml:

  1. Navigate to /themes/my_custom_theme/config/.
  2. Create a new file named theme.yml.

4.2 Defining Theme Metadata

The theme.yml file starts with metadata that identifies your theme within the PrestaShop system. This includes the theme name, version, author, and more.

Sample Metadata:

name: my_custom_theme display_name: My Custom Theme version: 1.0.0 author: name: "Your Name" email: "" url: ""

4.3 Setting Up Theme Hooks

Hooks are points within the PrestaShop codebase where you can attach your custom functionality. In the theme.yml file, you can specify which hooks your theme will use.

Sample Hook Configuration:

hooks: custom_hooks: - name: displayMyCustomHook title: My Custom Hook description: Adds a custom area in the header.

By the end of this chapter, your theme.yml file should be set up with all the necessary metadata and hook configurations. This file serves as the blueprint for how your theme interacts with the PrestaShop system, so make sure it’s configured correctly.

Chapter 5: Creating Basic Templates

5.1 Header and Footer

The header and footer are integral parts of your website, appearing on nearly every page. They often contain essential navigation links, branding elements, and other functional components like search bars or shopping carts.

Steps to Create Header and Footer:

  1. Navigate to /themes/my_custom_theme/templates/.
  2. Create header.tpl and footer.tpl files.
  3. Add the necessary HTML and Smarty code to build these sections.

5.2 Home Page

The home page is often the first page visitors see, making it crucial for capturing attention and guiding users through your site.

Steps to Create Home Page:

  1. In the same /templates/ directory, create a home.tpl file.
  2. Add your layout elements, such as banners, product listings, and promotional sections.

5.3 Product Page

The product page is where you showcase individual products. It usually contains product images, descriptions, prices, and an “Add to Cart” button.

Steps to Create Product Page:

  1. Create a product.tpl file in the /templates/catalog/ directory.
  2. Add elements like product images, descriptions, and the “Add to Cart” button.

5.4 Category Page

The category page lists multiple products under a specific category, providing filters and sorting options to help users find what they’re looking for.

Steps to Create Category Page:

  1. Create a category.tpl file in the /templates/catalog/ directory.
  2. Add product grids, filters, and sorting options.

By the end of this chapter, you should have a set of basic templates that form the skeleton of your online store. These templates are the building blocks that you’ll continue to refine and expand upon in the following chapters.

Chapter 6: Working with Smarty Template Engine

6.1 Basic Syntax

Smarty is the template engine used by PrestaShop, allowing you to separate the business logic from the presentation layer. Understanding its basic syntax is crucial for effective theme development.

Key Syntax Elements:

  • Variables: {$variable_name}
  • Functions: {function_name parameter=value}
  • Comments: {* This is a comment *}

6.2 Variables and Functions

Smarty variables and functions enable you to inject dynamic data into your templates. For example, you can display a product’s name or loop through an array of product images.


smartyCopy code

<h1>{$product_name}</h1> {foreach from=$product_images item=image} <img src="{$image}" alt="{$product_name}"> {/foreach}

6.3 Conditional Statements

Conditional statements in Smarty allow you to control the flow of your templates. You can display different content based on certain conditions, such as whether a user is logged in or not.


{if $is_logged_in} <p>Welcome back, {$user_name}!</p> {else} <p>Please <a href="login">log in</a>.</p> {/if}

6.4 Loops

Loops are used to iterate through arrays or objects, making it easier to display lists of items, such as products or categories.


<ul> {foreach from=$categories item=category} <li>{$}</li> {/foreach} </ul>

By the end of this chapter, you should have a solid understanding of how to use Smarty in your PrestaShop 1.7 theme. Smarty’s capabilities allow you to create more dynamic, flexible templates that can adapt to various types of content and user interactions.

Chapter 7: Styling Your Template

7.1 Introduction to SCSS in PrestaShop

SCSS (Sassy CSS) is an extension of CSS that adds power and elegance to the basic language. PrestaShop 1.7 is optimized for SCSS, allowing you to take advantage of variables, nested rules, and more.

Why Use SCSS:

  • Easier to maintain
  • More modular
  • Advanced features like variables and nesting

7.2 Theme Customization

Your SCSS files will reside in the /assets/css/ directory within your theme folder. Here, you can override the default styles or add new styles to customize your theme.

Steps to Customize:

  1. Navigate to /themes/my_custom_theme/assets/css/.
  2. Create or edit .scss files.

7.3 Creating SCSS Files

When creating SCSS files, it’s a good idea to separate them based on their function. For example, you might have one file for variables, another for the header, and so on.

Example File Structure:

  • _variables.scss
  • header.scss
  • footer.scss
  • product-page.scss

7.4 Compiling SCSS to CSS

After writing your SCSS, you’ll need to compile it into standard CSS that browsers can interpret. You can use tools like Sass, Gulp, or Webpack for this.

Steps to Compile:

  1. Install a compiler like Sass.
  2. Run the compile command, usually something like sass input.scss output.css.

By the end of this chapter, your theme should be well-styled and visually appealing. The use of SCSS will make it easier for you to manage styles and make future updates.

Chapter 8: Adding JavaScript Functionality

8.1 Including JavaScript Files

JavaScript is essential for adding interactivity to your PrestaShop theme. Your JavaScript files will typically reside in the /assets/js/ directory within your theme folder.

Steps to Include JavaScript:

  1. Navigate to /themes/my_custom_theme/assets/js/.
  2. Create or edit .js files.

8.2 Writing Custom Scripts

Custom scripts can enhance your theme by adding features like sliders, form validations, or AJAX-based loading. When writing custom scripts, keep them modular and well-commented.

Example Script:

// Toggle mobile navigation document.addEventListener("DOMContentLoaded", function() { const menuButton = document.querySelector('.menu-button'); const navMenu = document.querySelector('.nav-menu'); menuButton.addEventListener('click', function() { navMenu.classList.toggle('open'); }); });

8.3 Using PrestaShop’s Core JavaScript API

PrestaShop 1.7 comes with a core JavaScript API that provides useful methods and hooks. Utilizing this API can save you time and ensure compatibility.

Example Using Core API:

prestashop.on('updateCart', function(event) { const cartCount = event.resp.cart.products_count; document.querySelector('.cart-count').textContent = cartCount; });

By the end of this chapter, your theme should have the necessary JavaScript functionality to provide an interactive and user-friendly experience. Whether it’s a simple image slider or a more complex feature like AJAX-based product filtering, JavaScript is the tool that will bring your theme to life.

Chapter 9: Creating Custom Modules

9.1 Understanding Module Architecture

Modules in PrestaShop allow you to extend the platform’s core functionality. Whether you need a custom payment gateway or a unique feature for product recommendations, modules are the way to go.

Key Components:

  • PHP files for server-side logic
  • Smarty templates for the frontend
  • JavaScript for client-side interactivity

9.2 Building a Simple Module

Creating a module involves several steps, from setting up the directory structure to writing the code and registering the module in PrestaShop.

Steps to Create a Simple Module:

  1. Navigate to /modules/ in your PrestaShop directory.
  2. Create a new folder for your module, e.g., my_custom_module.
  3. Inside this folder, create the main PHP file, e.g., my_custom_module.php.

Sample my_custom_module.php:

<?php if (!defined('_PS_VERSION_')) { exit; } class My_Custom_Module extends Module { public function __construct() { $this->name = 'my_custom_module'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'Your Name'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('My Custom Module'); $this->description = $this->l('Adds a custom feature to the store.'); } public function install() { return parent::install(); } }

9.3 Integrating the Module with the Theme

Once your module is created, you’ll need to integrate it with your custom theme. This often involves adding Smarty hooks in your template files where the module will display its output.

Example Integration:

  1. In your module PHP file, register a hook, e.g., displayHome.
  2. In your home.tpl file, add the Smarty hook: {hook h='displayHome'}.

By the end of this chapter, you should know how to create a basic custom module and integrate it with your PrestaShop theme. Custom modules allow you to add virtually any feature to your online store, making them a powerful tool for customization.

Chapter 10: Testing and Debugging

10.1 Testing on Different Devices and Browsers

Before launching your theme, it’s crucial to test it on various devices and browsers to ensure compatibility and a consistent user experience.

Testing Checklist:

  • Desktop browsers: Chrome, Firefox, Safari, Edge
  • Mobile devices: Android, iOS
  • Tablet devices: iPad, Android tablets

10.2 Debugging Tools

Debugging is an inevitable part of development. PrestaShop comes with built-in debugging features, and you can also use browser developer tools for frontend debugging.

Recommended Debugging Tools:

  • PrestaShop Debug Mode
  • Browser Developer Tools
  • PHP Debugging with Xdebug

10.3 Common Issues and Solutions

During the testing phase, you’re likely to encounter some issues. It’s essential to know how to troubleshoot common problems.

Common Issues:

  • Broken layout
  • JavaScript errors
  • Module conflicts

Troubleshooting Steps:

  1. Check the browser console for errors.
  2. Use PrestaShop’s Debug Mode to identify PHP errors.
  3. Review your code for syntax errors or logical issues.

By the end of this chapter, you should have a well-tested theme that’s free of bugs and ready for deployment. Testing and debugging are critical final steps to ensure that your theme meets quality standards and provides a smooth user experience.

Chapter 11: Theme Packaging and Distribution

11.1 Creating the Theme Zip File

Once your theme is tested and debugged, the next step is to package it into a ZIP file for distribution. This ZIP file will contain all the necessary files and folders that make up your theme.

Steps to Create Theme Zip File:

  1. Navigate to your theme’s root directory, e.g., /themes/my_custom_theme/.
  2. Select all files and folders.
  3. Compress them into a ZIP file, e.g.,

11.2 Theme Documentation

Good documentation is essential for any software product, and PrestaShop themes are no exception. Your documentation should explain how to install the theme, configure settings, and use its features.

Key Sections in Documentation:

  • Installation guide
  • Configuration settings
  • How to use custom modules
  • Troubleshooting tips

11.3 Submitting to PrestaShop Addons Marketplace

If you plan to sell your theme, the PrestaShop Addons Marketplace is a great platform. To submit your theme, you’ll need to adhere to certain guidelines and go through a review process.

Steps to Submit:

  1. Create an account on the PrestaShop Addons Marketplace.
  2. Follow the submission guidelines, which may include providing additional files or screenshots.
  3. Submit your theme for review.

By the end of this chapter, you should know how to package your theme for distribution and understand the importance of good documentation. Whether you’re distributing your theme internally within your organization, offering it for free, or selling it on a marketplace, these final steps are crucial for a successful launch.

Chapter 12: Best Practices and Tips

12.1 Code Quality

Maintaining high code quality is essential for the long-term success of your theme. This includes writing clean, well-commented code and adhering to coding standards.

Best Practices:

  • Use meaningful variable and function names.
  • Comment your code to explain complex logic.
  • Follow PrestaShop’s coding standards.

12.2 Performance Optimization

A fast-loading website provides a better user experience and can positively impact SEO. Optimize your theme for performance to ensure quick load times.

Optimization Tips:

  • Minimize the use of large images.
  • Use lazy loading for images and videos.
  • Optimize CSS and JavaScript files by minifying them.

12.3 SEO Considerations

Search Engine Optimization (SEO) is crucial for the visibility of your online store. While PrestaShop is already SEO-friendly, your theme should also adhere to best practices.

SEO Best Practices:

  • Use semantic HTML tags.
  • Ensure that all images have alt attributes.
  • Implement schema markup for products.

By the end of this chapter, you should have a comprehensive understanding of the best practices and tips for maintaining and improving your PrestaShop theme. These guidelines will help you keep your theme up-to-date, user-friendly, and optimized for performance and SEO.


Congratulations, you’ve reached the end of this comprehensive guide on creating a custom template for PrestaShop 1.7. From setting up your development environment to packaging your theme for distribution, we’ve covered every process step.

This guide aims to serve as a valuable resource for both novice and experienced PrestaShop developers.

Happy coding!

Leave a Comment