Static Resources and Elements
Last updated Sep 25th, 2019 | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$311 per month—let's make that $500!
Learn moreThe Problem¶
When working in collaboration, teams of developers and designers often collaborate via Subversion (SVN) to make development easier between multiple people. MODX, however, stores its data in the database. This has many benefits generally, but DB-stored code cannot be version-controlled via SVN.
However, the solution in MODX Revolution is quite simple.
The Solution¶
For Resources, it's simple. Just use Static Resources, and point the content to a file in your SVN checkout.
The following is relevant to older versions of MODX. For MODX 2.2.x, as with static resources, simply use Static Elements. Static Elements have the further advantage of being able to use Media Sources.
For Elements, all you need is a simple "include" snippet. The code:
if (!file_exists($file)) return '';
$o = include $file;
return $o;
You can then call it like so in your Static Resources:
[[include? &file=`/path/to/my/svn/checkout/snippet.php`]]
And you're done. You can also use tags within the 'file' parameter, such as this:
[[include? &file=`[[++assets_path]]/js/myscript.js`]]
Conclusion¶
This allows you to easily manage content via SVN. It can be achieved with Templates and TVs as well; just plop the include snippet wherever you need filesystem-based files.
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$311 per month—let's make that $500!
Learn more