We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18331
    • 20 Posts
    Hello,

    I was wondering is it available (and if yes - how this is working) to use TV value in external files. For example js or css?

    For example I have text TV called "background color" and i would like to write this value in my css file as (for example)
    body {background-color:[*background-tv*]}
    .

    Thanks in advance!
      • 23571
      • 223 Posts
      I use a modx document as my CSS file and then use getResourceField to grab the TV. See the call below.

      background: url([[++site_url]]assets/endusers/[[!getResourceField? &id=`1` &field=`headerImage` &processTV=`1`]]) [[!getResourceField? &id=`1` &field=`horizontalPosition` &processTV=`1`]] [[!getResourceField? &id=`1` &field=`verticalPosition` &processTV=`1`]];
        • 23571
        • 223 Posts
        Sorry:
        background: url([[++site_url]]assets/endusers/[[!getResourceField? &id=`1` &field=`headerImage` &processTV=`1`]]) [[!getResourceField? &id=`1` &field=`horizontalPosition` &processTV=`1`]] [[!getResourceField? &id=`1` &field=`verticalPosition` &processTV=`1`]];
          • 18331
          • 20 Posts
          Thanks for reply! But still the css is document in modx. I mean you're writing css in modx document body? Or i don't understand the idea ? smiley
            • 23571
            • 223 Posts
            I just realized that this was an Evo question. This is essentially the same solution, just uses Evo snippets: http://www.gregorysmart.com/2010/02/11/create-a-dynamic-css-file-in-modx/
              • 18331
              • 20 Posts
              Thanks for tutorial! Didn't knew that before. I was using a simple workaround for that just by creating something like this in <head>:

                  <style type="text/css">
                  body {background-color:[*body-color*]} // direct TV or getting TV value by GetField
                  </style>
              


              With your tutorial i think i still need two css files. One that I could edit with some software over ftp and one additional one editable in modx. Right?
                • 23571
                • 223 Posts
                I tend to put all of my CSS entries into a single file, but yes, you could use two.
                  • 18331
                  • 20 Posts
                  Two files actually it's a little bit stupid, but.. I like editing css over ftp, it's much comfortable for me.

                  Anyway it's the only way to do such a thing? I was wondering maybe exist some code, syntax or snippet fo use it directly in css file. You know like opening style.css over ftp, and just entering the similar thing "body {background-color:[*body-color*]}" directly into css file, but i think where are no solution for that?
                    • 23571
                    • 223 Posts
                    I think it is possible to access some of the modx elements from external files, but not sure that it's possible to execute snippets externally.
                      • 3749
                      • 24,544 Posts
                      You can keep the css in a file and use a snippet to inject it into the head of the document with:

                      $modx->regClientCSS('url/of/css/file');


                      http://rtfm.modx.com/display/Evo1/regClientCSS



                      ---------------------------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
                      MODx info for everyone: http://bobsguides.com/MODx.html
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting