We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15987
    • 786 Posts
    I have my css as a modx document for my site.

    I am currently using a template variable to select the image to display at the top of each page. To get this to work correctly I had to take the css for the header and put it in my template.

    This works great, but I would really like to get the css back in the document.

    Does anyone know if there is a way to get the value of the template varible into the css document? I tried to put the tv [*title_image*] in the css document and it just returned a blank value for every page.

    the template variable is an option group containing a list of the image names (i.e. title.jpg, title-p.jpg).

    Any help would be appreciated.

    Kyle
      • 32241
      • 1,495 Posts
      If you have a different images for every pages, then it’s best to put your CSS on your template, considering we need to use external CSS to have the browser to cached the CSS file, instead of we need to load it on every page. If you have a changing css that is dynamically changing, using it as an external will cause the browser to get confused, because they try to cache a dynamic CSS file which needs to be reupdated on every page

      If you still insist to do it, you can make your internal css as a template variables and call other image tv inside this tv which is possible in MODx.

      Hope that helps.
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 15987
        • 786 Posts
        Wendy,
        Thanks for the reply, I hadn’t thought about the caching issue, so I will just leave it with the image css in my template.

        thanks again,
        Kyle
          • 7923
          • 4,213 Posts
          You can though get the linked css file to load on every call, if you would pass changing variable to it, like timestamp for example. Check this.


            "He can have a lollipop any time he wants to. That's what it means to be a programmer."
            • 15987
            • 786 Posts
            Thanks for the artcle doze. I think that there is more of a problem than the caching issue though. I can’t get the value of the tv into the css document so I’m not sure it is possible to have dynamic code in your css document without using a snippet. And I don’t think it is worth writing one for what I want to do, the way I have it works fine for now.

            thanks,
            kyle
            • TVs can’t work in a css document, because the css document has no template. And even if it did, how would the content of the TV be determined...for the css document? You want its value for the document the css file is styling.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
              • Actually, why couldn’t you use TVs and just create a "blank css" template that had nothing in it except maybe a comment header? Doesn’t solve the issue of what the TV the document is for though... suppose you could do some cookie or DB mojo...
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • Quote from: rthrash at Apr 18, 2006, 07:50 PM

                  Actually, why couldn’t you use TVs and just create a "blank css" template that had nothing in it except maybe a comment header? Doesn’t solve the issue of what the TV the document is for though... suppose you could do some cookie or DB mojo...

                  Tried that one...then was scratching my head to figure out how to get the value I wanted from the TV for the document the css document is styling...

                  Since it was for small things, setting background colors for different sections, I just did it in the template head. It really wasn’t worth trying to code something complex and take up the resorces and processing time for something so simple.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 15987
                    • 786 Posts
                    Susan, I think I have come to the same conclusion. For a small thing like changing a background image, there is no need to code something complex when it works in the template header. Or I should say I don’t want to spend the time coding something complex.