...
An asset type is a resource that is used in the Publisher and Store. WSO2 Enterprise Store (ES) ships some default assets: Gadgets and Sites. An asset extension allows you to define a new asset type with a set of custom behaviors and views. The behaviors defined within an asset extension are only applicable for that specific asset type.
When should I use an asset extension?
ES automatically generates a set of basic views and provides generic business logic for CRUD (create, read, update and delete), lifecycle and subscription operations. However, the generic behavior may not always be sufficient, and you may want to define your own business logic for a CRUD operation or change a generic view. For example:
...
Therefore, you need to create a new asset extension in such instances to be able to add a new customized asset type to ES.
Overall structure of an asset extension
The asset extensions are maintained in the assets
directory. The asset extension directories for the Publisher and Store are as follows:
...
The following diagram explained the folder structure of the assets
directory. This diagram shows a number of asset extensions along with the default extension. The default directory contains sub-folders that handle the behavior and views of a generic asset type. In addition, the default
directory provides an example of the directory structure that you need to maintain when adding an asset extension. However, note that each of the listed items are optional. Therefore, an asset extension need not have all of the items indicated in the following diagram. The ES extension model will automatically inherit the CRUD logic and pages from the default
extension folder.
Asset extension components
The following diagram illustrates the structure of an asset extension:
...
- Define a callback method that allows the CRUD logic to be modified.
- Define new pages and APIs.
- Override the current pages and APIs.
- Change the RXT properties of an asset.
- Define a callback method, which is called on the asset data prior to rendering.
For more information, see asset.js Script.
- A
themes
directory- Any partials, JS scripts or CSS files for new or overridden pages are added in this directory.
- This directory is used to customize the view in ES. For more information, see Asset ExtensionCustomizing the view.
- An
apis
directory- Controllers, which either override the existing APIs or add new endpoints, are added in this directory.
- The APIs defined in the
asset.js
asset.server
callback method are looked up in this folder.
- A
pages
directory- Controllers, which either override the existing pages or add new pages, are added to this directory.
- The pages defined in the
asset.js
asset.server
callback method are looked up in this folder.
Customizing the view
The themes
directory is used to customize the view. ES views are rendered using the Caramel MVC framework. The extension model works together with the Caramel framework, to determine from which location a view should be loaded. When a resource is consumed by the Caramel framework, the extension model examines the request URI to determine if the request originated for a particular asset type. Thereafter, it will attempt to locate the resource from within the asset extension directory. This allows any of the corresponding partials of a view to be overridden individually, based on a specific asset type. However, if needed you can also override the partials of a view globally, so that it affects all the asset types.
Related Links
Child pages (Children Display) |
---|