We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17786
    • 9 Posts
    Hi -- I’m relatively new to MODx but having an awful lot of fun with it! smiley

    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
      • 4172
      • 5,888 Posts
      you can use getResources to pull all of them in your head-section.

      But you can also store your CSS in chunks and create a checkbox-tv to call them.
      use as input-option-values something like that:
      CSS A==[[$CSS_A]]||CSS B==[[$CSS_B]]||CSS C==[[$CSS_C]]||CSS D==[[$CSS_D]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 27985
        • 54 Posts
        Bruno,

        Would you please elaborate on your solution.
        Is [[$CSS_A]] just a placeholder or how does it correspond to the chunk that you would be including? I don’t understand how the css gets included after you check which items apply.
        I hope you will write some more, I think it could help me understand how to use template variables etc.

        Thanks

          MODx 2.0.6
          PHP 5.3.3
          MySQL 5.1.50