Usage
Create a new plugin, it's main class must extend Ryssbowh\CraftThemes\ThemePlugin
.
You could for example create a themes
folder at the root, and add it as a composer repository by modifying the root composer.json
:
"repositories": [ { "type": "path", "url": "themes/*", "options": { "symlink": true } } ]
You can then require your theme as any other package. When it's installed, enable it in the backend.
Partial themes
A partial theme will not be available to select in the backend, but it can be inherited from. Define a partial theme with the method isPartial(): bool
of the main class.
Asset bundles
Asset bundles can be defined in your theme class, in the $assetBundles
property, it's an array indexed by the url path :
[ '*' => [ CommonAssets::class ], 'blog' => [ BlogAsset::class ] ]
Bundle assets will be registered automatically, the '*' will be registered on every page.
By default, parent themes bundles will also be registered. This can be disabled with the property $inheritsAssetBundles
of your theme class.
Inheritance
Themes can extend each other with the method getExtends(): bool
of their main class.
Parent themes will be installed automatically when installing a theme in the backend.
Templates
Templates are inherited, that's the whole point isn't it ?
So if you call a template that isn't defined in your theme but exist in a parent theme, the parent template will be loaded.
Assets (images, fonts, etc)
Assets can be inherited through the twig function theme_url
.
If you have an image.jpg
defined in your theme in the images
folder, you can publish it with theme_url('images/image.jpg')
If you require an asset and the file is not present in your theme, it will look in the parent theme (if defined).
This inheritance can be disabled with the property $inheritsAssets
of your theme class.
Root template folder
It is recommended to not use the root templates
folder when using themes, if some templates are defined both in this
folder and in a theme, the root templates folder will take precedence.
A theme cannot override templates that have a namespace (ie other plugin templates), unless they register their templates roots with the '' (empty string) key.