This feature is available for all elements, including templates, snippets, chunks, and plugins.
How to Create
To create an element as a static element, simply check the Static box, select Media Source, and add the path to the file specific to that media source to the Static File input. You can also click the icon in the Static File input to open the MODX browser to select the file instead of typing it in manually.
This process is the same for all element types.
Files vs. Database
Keep in mind that MODX still stores the content in the database so that the element can be processed normally. MODX only checks the file content when the element is requested without caching, so be sure to clear the cache when developing. For this reason, static items may be most useful when working with uncached snippets or plugins, and somewhat less useful for templates and blocks.
To improve the editing experience with static items, there are a few additional features that can help automatically create items in the MODX database or automatically clear the cache for you.
Automatically Generate Static Items
You can automate the static item generation process in core. It removes the manual steps of creating a static item, marking the item as static, selecting the static item’s media source, and it automatically generates a file path name for your static file.
When an item is deleted or renamed, its associated file is also deleted.
Configure Automatic Static Items
- Go to System > System Settings. Select a Static Items theme.
- Enable static item automation for each item type you want to use the static item automation workflow. For example, enable
static_elements_automate_snippets
to use it for snippets, andstatic_elements_automate_chunks
to use it for chunks. - Select the default media source for static elements in
static_elements_default_mediasource
. - Specify the static elements base path where files will be sent in
static_elements_basepath
. For example:components/static/elements/
. - If necessary, select the default category to use for static elements in the
static_elements_default_category
parameter. - To ensure that the
tpl
extension works in templates, you need to add thetpl
extension to theupload_files
setting. MODX automatically generates static elements with this name.
File structure
Files will be created at the path: {static_elements_basepath}/{type}/{category}/{filename}.{extension}
in the specified media source. For example: components/site/elements/chunks/html/footer.chunk.tpl
.