Hi -- I’m relatively new to MODx but having an awful lot of fun with it!
I have an idea I’d like to use in a site I’m building. There’s a kludgey way to do this (which I can do on my own already) but I suspect there’s a more elegant, easier-to-maintain way to do this.
In a nutshell, I have a series of sub-documents that do/do not appear on a master page depending on the master’s page’s settings. Each of these sub-documents has its own CSS <link> statement that needs to be included in the master page’s <head> statement,
but only if the sub-document is set to appear on the master page. Each sub-document has a TV called "accompanying_css" that is populated with the full CSS <link> statement that that resource requires.
Here’s where it gets potentially kludgey. Getting the CSS for a particular sub-document to appear in the master’s <head> is a simple matter of using getResourceField to pull the TV named "accompanying CSS" from a particular resource.
<head>
[[getResourceField? &id=`[[~ID OF SUB-DOCUMENT]]` &field=`accompanying_css` &isTV=`true`]]
</head>
If you’ve got only one sub-document that may or may not appear, great. But say there are 10 potential sub-documents? You’ve got to put 10 of these statements in the template, one for each potential flavor. Kludge city.
So...what I would LIKE to be able to do is, when a particular set of sub-documents appear on a master page, the contents of each sub-document’s "accompanying_css" TV are somehow combined into a single TV that can be called ONCE from the master page’s <head>.
So rather than ten different calls, one for each potential flavor of sub-document, there’d be one catch-all that would include each ACTIVE sub-document resource’s CSS statement and render all the <link> statements from a single call.
I’m assuming this involves writing each of these CSS statements to a database table, then simply pulling all the records from the table at the same time with a single call from the <head> statement.
First, is this the right way to do this, or is there an easier way I’m missing?
Second...since I am a pretty big noob...how would I go about doing this?
Thanks in advance for the help!
M2