We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • It would be nice to be able to register CSS files for inclusion in the page header the same as you can .js files.
      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
      • 32963
      • 1,732 Posts
      Quote from: sottwell at Jun 22, 2005, 03:54 PM

      It would be nice to be able to register CSS files for inclusion in the page header the same as you can .js files.

      You mean via the $modx->regClientStartupScript() function?
        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
      • ummm... can you elaborate on that.
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • Ok...take the DocMan snippet. It’s quite an elaborate application on its own, and it is better that it have its own CSS file than to cram all that CSS markup into the main template CSS file, especially since the rest of the web pages won’t use it.

          The core has two API functions for including external javascript files, one in the head and one in the body.

          	# Registers Startup Client-side JavaScript - these scripts are loaded at inside the <head> tag
          	function regClientStartupScript($src) ...
          
          	# Registers Client-side JavaScript 	- these scripts are loaded at the end of the page
          	function regClientScript($src)
          


          In the DocMan snippet, I include an external javascript file:

          $src="assets/snippets/docman/js/selections.js";
          $modx->regClientStartupScript($src);
          


          Now, it is certainly possible to add a style sheet as I do in the snippet:

          $fm = "<style type='text/css'>
              @import url(assets/snippets/docman/style/docman.css);
          </style>";
          


          but it’s ugly, and I’m not completely sure that all browsers will accept a <style> tag in the middle of the body, let alone the include. It would be much nicer if there were an API function similar to that for javascript insertion to plug it into the head of the pages the snippet uses.
            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
          • LOL... sorry Susan! I meant Raymond. smiley Like showing an example. heh

            And now that I’ve read it I didn’t even realize that was there. I thought Raymond had yet something else in store for us for TP3.

            I agree completely though, we should be able to include via the API things in page headers. In-body styling causes validation to fail like you suspected.
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • It would only take cloning the regClientStartupScript($src) function, call it maybe regClientCSS($src), and replace the <script... parts with <style... parts. The general functionality is much the same. Although for neatness’ sake I would be inclined to insert it immediately following the </title> tag. Or perhaps immediately before the <body> tag.

              Of course, to avoid conflicts in the "cascade" part of CSS, a snippet designer has to be careful to make all his id and class tags unique. I prefer to use a prefix; dmDiv, dmH1, dmInput, etc, and this way I can style my snippet’s content without having problems with the main page content. Also, that helps with javascript keeping track of which buttons you’re doing what to.

              Hm. It occurs that perhaps in the meantime it would be possible to make an "on page prerender" plugin, and tie it to the snippet? Or do those only get tied in to templates? I still haven’t spent a lot of time investigating that.
                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
                • 32963
                • 1,732 Posts
                Quote from: sottwell at Jun 23, 2005, 05:40 AM

                Hm.? It occurs that perhaps in the meantime it would be possible to make an "on page prerender" plugin, and tie it to the snippet?? Or do those only get tied in to templates?? I still haven’t spent a lot of time investigating that.

                You can use a snippet to invoke a plugin but under normal circumyances the OnWebPagePrerender event is automatically invoked just before the html is sent to the browser

                you can add placeholders to your page and then use a plugin or snippet to add additional data to the page.

                  xWisdom
                  www.xwisdomhtml.com
                  The fear of the Lord is the beginning of wisdom:
                  MODx Co-Founder - Create and do more with less.
                • I worded that badly. I meant a plugin that would listen for the onPreRender event, and load the <link rel=’stylesheet.... /> tag in the head.
                    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
                    • 32963
                    • 1,732 Posts
                    Yep! That’s also a possibility
                      xWisdom
                      www.xwisdomhtml.com
                      The fear of the Lord is the beginning of wisdom:
                      MODx Co-Founder - Create and do more with less.