Implementing a parent theme

Parent theme can speed up the process of customisations' development, providing an opportunity to customise customisations, keeping it as DRY as possible.

Coding Standard

ScandiPWA v3 (currently in beta) supports implementing parent themes, which allow extending some custom theme that extends vendor theme. This functionality is convenient if one likes to use his own theme that extends scandipwa/source as the project’s base instead of scandipwa/source itself.

A step-by-step algorithm of implementing a parent theme

  1. Implement your custom theme, you can refer to this guide.

  2. Create a parent theme directory: app/design/frontend/<vendor>/<themename> or use the default app/design/frontend/Scandiweb/pwa_parent.

  3. Reference that directory in the scandipwa.json file in the root of your project, field parentRoot. The path should be relative to app/design/frontend directory.

    "parentRoot": "<vendor>/<themename>"
  1. Move your custom theme’s contents there (mv -r pwa/* pwa_parent/*) and then erase the pwa directory.

  2. Restart the project in order to re-create the pwa folder from scratch.

  3. If in your custom theme you had anything changed in the files that now populate the pwa directory, migrate the changes back.

  4. Start implementing a theme on top of your theme! Work in the pwa directory just as you are used to.

  5. Implement desired logic!

    • Extending files. First you need to import something you want to extend. To import files from parent theme use the alias Parent<...>, to import from source theme use the alias Source<...>. E.g. to import AddToCart component (and extend it) use the following:
     // To extend source component
     import SourceAddToCart from 'SourceComponent/AddToCart';
     class AddToCart extends SourceAddToCart { ... }
     // Or to extend parent theme's component
     import ParentAddToCart from 'ParentComponent/AddToCart';
     class AddToCart extends ParentAddToCart { ... }
    • Using components. To import component and use it somewhere in your application (not to extend it) use the regular Component/<ComponentName> alias. When resolving a file, Fallback plugin is going to look in the following directories subsequently:
    1. Custom theme (app/design/frontend/.../pwa)
    2. Parent theme (parentRoot in scandipwa.json)
    3. Vendor theme (src/scandipwa/source)