We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22303 MODX Staff
    • 10,725 Posts
    Quote from: BobRay at Mar 05, 2009, 11:17 AM

    Quote from: TobyL at Mar 05, 2009, 05:17 AM

    I’ve used this on occasion for stylesheets. It’s a very simple way of delivering stylesheets where I wanted modx tags to be parsed without having to embed the styles in the document itself .
    Can you describe that process in more detail for me. I think I understand, but I’m not sure.
    It’s the same concept as with any HTML, XML, or plain text Content Type; you use MODx Tags to dynamically construct the output, regardless of how it is done and what the resulting content is. It can even be binary content. And there is now a way to set custom HTTP response headers for each Content Type you define, though this may need some testing and interface work.

    This allows CSS or even javascript files to be dynamically constructed, just like regular HTML documents, managed in the MODx tree, and referenced like any other document in the content, e.g.
    <script type="text/javascript" src="[[~27]]" />
    where the content for Resource 27, assigned a Content Type that has a mime-type of text/javascript, might look like something like...
    myDynamicVariable = [[!GetMyDynamicVariableValue]];
    

    That’s a bit oversimplified for brevity, but I think you get the idea.

    Same thing can be done with, for instance images. You just use a script to produce the output, even if it’s a Static Resource with a binary Content Type that just echo’s the contents of a file to the browser.
      • 30223
      • 1,010 Posts
      I can’t give you a real world example (As I said, it was in the past) but this should give you an idea.

      Scenario: A design with a simple css background masthead image where the client wants to be able to change the image.

      Solution:
      A TV with default set to @INHERIT and imput type ’image’ (named ’cssBackgroundImage’)
      A snippet which fetches the TV. Something like this: (named ’getCssBgImage’)
      <?php
      $docid = isset($_REQUEST['cssid'])? abs($_REQUEST['cssid']):0;
      if($docid)
          $tv = $modx->getTemplateVarOutput('cssBackgroundImage',$docid);
      //default is hard-coded
      $img = isset($tv['cssBackgroundImage']) ? $tv['cssBackgroundImage'] : 'assets/images/css/default_background.png';
      return $img;
      ?>
      


      A document holding the stylesheet.
      Content-type: ’text/css’
      Template: blank
      Alias: styles.css
      Content:
      /*plenty of other css*/
      
      #masthead{
         height:200px;
         padding:0;
         background:url('[!getCssBgImage!]') top left no-repeat;
      }
      


      In the Template add this:
      <link rel="stylesheet" href="styles.css?cssid=[*id*]" type="text/css" media="screen" />
      


        • 3749
        • 24,544 Posts
        @OpenGeek: Thanks. Will the regClient ... functions be deprecated, or do they still have a use?

        @TobyL: Thanks for the great example. I tried implementing it to make sure I understand it and think I have it working (it displays the default BG image, at least), but I absolutely can’t get FURLs working on localhost. Having a one-line .htaccess with just "rewrite engine on" gives me a server 500 error.

        I can never remember the syntax for sending extra parameters in an href with FURLs off. This doesn’t do it and I can’t find what does:

        <a href="http://localhost/index.php?id=12 ?cssid=29"> 


        Can somebody refresh my memory on this?

          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
          • 30223
          • 1,010 Posts
          <a href="http://localhost/index.php?id=12&cssid=29">
            • 3749
            • 24,544 Posts
            Got it (finally). laugh

                $tv = $modx->getTemplateVarOutput('cssBackgroundImage',$docid);


            Needs to be:

                $tv = $modx->getTemplateVarOutput(array('cssBackgroundImage'),$docid);


            I kept thinking there was something wrong with my non-friendly URL but it was the code.

            I don’t understand why $docid is necessary (though it is). In the getTemplateVarOutput() call it’s optional and is supposed to default to the current document (which is what should be set in $_REQUEST[’cssid’], no?)

              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
              • 30223
              • 1,010 Posts
              Because getTemplateVarOutput is called by the document which holds the css (via the snippet) which is different from the document which holds TV value. Without $docid it would try to find the TV for the css document which if it existed would be the same for all document requests.
                • 3749
                • 24,544 Posts
                Quote from: TobyL at Mar 08, 2009, 06:49 AM

                Because getTemplateVarOutput is called by the document which holds the css (via the snippet) which is different from the document which holds TV value. Without $docid it would try to find the TV for the css document which if it existed would be the same for all document requests.

                (duh) Thanks.  Obvious once you get it and also explains why the doc ID can’t be sent as a parameter in the snippet call.


                  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
                  • 23491 ☆ A M B ☆
                  • 1,056 Posts
                  Quote from: OpenGeek at Mar 05, 2009, 05:49 PM

                  Quote from: BobRay at Mar 05, 2009, 11:17 AM

                  Quote from: TobyL at Mar 05, 2009, 05:17 AM

                  I’ve used this on occasion for stylesheets. It’s a very simple way of delivering stylesheets where I wanted modx tags to be parsed without having to embed the styles in the document itself .
                  Can you describe that process in more detail for me. I think I understand, but I’m not sure.
                  It’s the same concept as with any HTML, XML, or plain text Content Type; you use MODx Tags to dynamically construct the output, regardless of how it is done and what the resulting content is. It can even be binary content.

                  Exactly, well said. For example, last week I had to ADD my own Content-type: "application/pdf" via the Site Configuration page. Now I am creating dynamic PDFs (via custom snippet and FPDF class) to output Daily and Weekly schedule information. This allows me to treat the PDF as a MODx document, which is ideal whenever dealing with document permissions smiley
                    Mike Reid - www.pixelchutes.com
                    MODx Ambassador / Contributor
                    [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                    ________________________________
                    Where every pixel matters.
                    • 3749
                    • 24,544 Posts
                    Quote from: pixelchutes at Mar 09, 2009, 03:54 PM

                    Exactly, well said. For example, last week I had to ADD my own Content-type: "application/pdf" via the Site Configuration page. Now I am creating dynamic PDFs (via custom snippet and FPDF class) to output Daily and Weekly schedule information. This allows me to treat the PDF as a MODx document, which is ideal whenever dealing with document permissions smiley

                    I did the same myself in Revo to check out Content-Type although my PDFs weren’t dynamic. Cool idea. smiley
                      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