Chapter 3. Using Context and its Methods

In PrestaShop, the Context object is something close to (but unfortunately not as flexible as) a service container (or dependency injection container) that you can have in other frameworks. This container is filled with common objects (such as cookies, current language, and so on), and services (such as Smarty).

In this chapter, we will learn how to:

  • Use the l method and make your module multilingual
  • Use the addCSS and addJS methods to improve the ergonomy in the front office

Looking at the Context object

The Context objectis a directory containing a list of objects. It is available in controllers and modules, and you can access it this way:

$this->context;

If you are not in a controller or a module, you can ...

Get PrestaShop Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.