Magnolia 5.3 reached end of life on June 30, 2017. This branch is no longer supported, see End-of-life policy.
STK resources are accessible in STK > Resources and can be changed inline. This functionality relies on the Resources module. Resources used in the STK include CSS sheets, JavaScripts and template images.
In the STK resources are referenced in the Theme configuration in STK > Themes. Resources can also be added in the template prototype or a template definition.
Node name | Value |
---|---|
pop | |
cssFiles | |
jsFiles | |
init-libraries | |
farFutureCaching | true |
link | /resources/templating-kit/js/scriptloader-libraries.js |
init-plugin | |
init-theme |
It is not necessary to store resources in the resources
workspace. You can link to any valid internal or external URL.
See Themes for more information about how resources are used in the STK.
The following resource types can be created in STK > Resources:
/templating-kit/themes/pop/img/bgs
and /icons
.Processed CSS
.Processed Javascript
.When a resource (CSS or JavaScript) is of type Processed, its content is interpreted as a FreeMarker template. You can use FreeMarker constants, variables and expressions inside the resource. You can also implement a custom model class and access the model's methods from inside the CSS or JavaScript document. The model class is defined in the resource's properties dialog. You can use any Java logic or Magnolia functionality. See Advanced tab below for more information.
To create a new resource item:
Depending on the resource type selection, Edit Item opens one of three dialogs:
editCode
control for entry of CSS or JavaScript code.In the Advanced tab:
Resources are typically CSS files, JavaScript, images that rarely change (for example, logos). A resource can be either rendered as is or it can be pre-processed. Most resource files sent to the browser. The resource loading logic is based on URI mapping. Where you store the resources should be determined by how those resources will be used.
/WEB-INF/lib
and any classes and resources in /WEB-INF/classes
.The advantage of storing resources in a module JAR is that the resources become part of the software lifecycle and follow the same release process as code. Since such resources are not editable inline, this approach works for items you don't need to edit often such as template scripts, background graphics and logos.
The path for resources served from classpath is:
http://<domain>/<contextPath>/.resources/<path-to-file>
The URI mapping configuration that resolves resources from a location that starts with /.resources
(note the dot) is in the Configuration app > /server/filters/servlets/ClasspathSpoolServlet
.
Magnolia uses the dot naming convention for resources in the classpath to avoid confusion with file location names assigned by developers. This is a convention that is used in other file locations too, such as .magnolia
.
For loading bypassed and non-processed resources you can add custom resource loaders that implement the info.magnolia.module.resources.loaders.ResourceLoader
interface. The FileSystemReosourceLoader
is an example of such a loader. It allows you to load resources from a custom file system path. You can define one path in the loader's configuration. The order of the loaders can be changed by moving the loader node up or down the tree.
Node name | Value |
---|---|
modules | |
resources | |
config | |
resourceLoaders | |
classpathLoader | |
class | info.magnolia.module.resources.loaders.ClasspathResourceLoader |
fileSystemLoader | |
class | info.magnolia.module.resources.loaders.FileSystemResourceLoader |
path | /home/jsmith |
You can make resources visible and editable inline by storing them in the resources
workspace. This is a useful strategy for development and testing purposes since it makes changing resources quick and allows you to override a resource in the classpath. However, generally this is not the best practice for production. The path for files served from the resources
workspace is http://<domain>/<contextPath>/resources/<path to file>
. For example: /resources/templating-kit/themes/pop/css/styles.css
.
The URI mapping configuration that resolves resources from a location that starts with /resources
(note the absence of the dot) is in the Configuration app > /server/URI2RepositoryMapping/mappings/resources
. Note that if a resource is marked as bypassed in the workspace, the system looks for the resource in the classpath.
You can also access resources using the WebDav module or the CMIS module.