Search code examples
apostrophe-cms

Template overriding in custom npm-modules in Apostrophe CMS


In order to have a common setup in most of my Apostrophe projects, I plan on building some custom npm-modules to bundle them and add them to my projects. Some of the features I would like to do in them, appart from adding widgets and backend functionality, is editing official apostrophe modules' setup (e.g., setting up default page types for apostrophe-pages) and overriding nunjuck blocks and/or templates.

Both things can easily be overwritten on a project-level configuration with Apostrophe's implicit subclassing mechanism, so my goal of sharing a common base setup for different projects could be achieved with a custom boilerplate, although I would lose the ability of upgrading my defaults by releasing new versions of my node modules.

All in all, I was thinking in a Maven-style dependency hierarchy like this:

Apostrophe npm modules <- custom npm modules <- project modules

Coming form a Java and Maven based CMS, I understand I will need to change my way of thinking in many things, so: is what I'm trying to do possible and does it make sense in the Apostrophe world? What would be "The Apostrophe Way" to achieve something like this? Do I need to create a custom npm module to with the moog option improve for each module I want to extend?

Thanks in advance.


Solution

  • Even in the npm_modules directory, apostrophe will scaffold out base modules first and modules that extend those modules second, meaning your custom npm modules will follow the same inheritance chain as the official apostrophe modules. You can override them the same way you would any other apostrophe module.

    meta module (apostrophe-pieces) > custom-pieces (piece extension, custom npm module) > custom-pieces (project-level overrides)

    You would just selectively override files and methods in lib/modules/ the same way you'd override parts of apostrophe-blog, like lib/modules/custom-pieces/views/widget.html

    Am I correctly understanding the way you want to override things?