• Attaching a CSS file to a template?#

  • landollweb Reply #1, 4 months, 2 weeks ago

    Reply
    This is a pretty basic question, but I haven't been able to find an answer searching through the docs or the forum...

    What is the most straightforward way to include an external CSS file in a template? Or is that even what you want to do to apply CSS to your html? I'm going around in circles, here...

    I've seen plenty of places where the docs say you can, but nothing that really explains how. I found a bit about making a function that uses regClientCSS... hmmm, that doesn't seem like what I need... I also noticed when I tried creating a resource of CSS type, that it asks for what template to use, but that doesn't make any sense. What if I need to use this CSS object with multiple templates?

    Thanks in advance for your patience... (I'm not usually this high-maintenance.) <grin>


  • sottwell Reply #2, 4 months, 2 weeks ago

    Reply
    1. Use the normal HTML link tag in your template's head to link to an external CSS file, just as you would for any HTML document.

    2. If using a resource for your CSS, give it a template of "None". Again, in this case use the ordinary HTML link tag to load the CSS resource.


  • landollweb Reply #3, 4 months, 2 weeks ago

    Reply
    Probably should have guessed that... still finding my way around in the system. Thanks for the quick reply, Susan.


  • sottwell Reply #4, 4 months, 2 weeks ago

    Reply
    This may be useful... http://rtfm.modx.com/display/revolution20/Making+Sites+with+MODx

    Note: Static elements and Media Sources

    With Revo 2.2, templates can be stored in the file system easily by checking the "is Static" checkbox and specifying the location of the file for the template. You can either select the base path from a Media Source and enter the remaining path information, or if you select NONE as the media source specify the absolute path to the file.

    For example, you could create a "Templates" media source that would point to some folder in your installation, put your templates in that folder, select that media source and just enter the filename.

    Media Sources and static elements add a whole new dimension to MODx.


  • landollweb Reply #5, 4 months, 2 weeks ago

    Reply
    Good to know, I think I will probably want to go that route. What places should I avoid storing my files, if I don't want them touched during a system upgrade?


  • Frogabog Reply #6, 4 months, 2 weeks ago

    Reply
    As far as I understand it, after doing a number of upgrades (and downgrades), the upgrades themselves won't touch any of your files. You can store your files anywhere on the filesystem that you like, including locations completely outside of the MODX filesystem.

    When upgrading, one loads the new files onto the server, overwriting only the files it includes. As such, any custom files residing in the filesystem remain as they were. Upgrading MODX is actually very simple and painless.

    However, if you're using any of the custom site packages available (i.e. MODX Boilerplate or Flexibility), running an update of the package itself will overwrite all of the files on your site that retain the original file names from the package. The solution to that would be to change the folder/file names before upgrading the package. Which of course breaks your site unless you make the name change right after the initial installation and work from the new directories instead of the ones shipped with the package. If you upgrade site packages this way, you'll end up with a new installation of the package as intended, with the original file names that will have to be manually transferred to your alternately named files and folders.

    I haven't figured out how to deal with the document/resources while doing this however. Assuming the site package creates resources/documents/pages for you, those could be overwritten. I do hope someday to see a solution for this problem so that site packages could be updated.


  • BobRay Reply #7, 4 months, 2 weeks ago

    Reply
    One common place for CSS files is under

    assets/css/


    If you're looking for a CSS file for a MODX extra, they are most often found in:

    assets/components/componentname/css/


    The assets directory is a good place for them because it's pretty much guaranteed to be completely untouched during upgrades to MODX. And in Revolution, things that need to be accessible by URL (like CSS and JS file), should got there because the core directory can be moved outside the web root where it's not web-accessible.


    ---------------------------------------------------------------------------------------------------------------
    PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
    MODx info for everyone: http://bobsguides.com/MODx.html


  • landollweb Reply #8, 4 months, 1 week ago

    Reply
    Good, that's what I was guessing. I'm creating entire site themes, with groups of similar templates and associated css, js, etc., and I noticed in the docs that was one of the recommended locations for my custom assets. Just wasn't sure what the implications were, or what the customary practice was for this system.

    Thanks for taking time to respond to my questions, everyone. Greatly appreciated!