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

    I am using MODx version 0.6.9.1, I am calling a snippet before the doctype tag of my template.

    [[snippet1]]
    <!DOCTYPE ...

    The content of the snippet is:
    <?php
    $modx->setPlaceholder(’templatePath’, ’assets/templates/site_template/’);
    ?>

    The snippet is not outputting any html, it is just setting a placeholder, but there is a blank line in the rendered html where the snippet was placed.
    Does anyone know of any way to get rid of the blank line?

    Thanks smiley
      • 11975
      • 2,542 Posts
      Hi,

      you could use a plugin for this with some php to remove blank lines

      Here is a sample


      $e = &$modx->Event;

      switch($e->name) {
      case ’Choose the best event’: 
        $output = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $modx->documentOutput);
        $modx->documentOutput = $output;
      break;
      }


      I’m not sure about the modx event to choose, perhaps OnWebPageComplete

      :-)

      P.S:  all blank lines in your html will be removed

        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 7231
        • 4,205 Posts
        Try putting the snippet on the same line as the DOCTYPE, it it does not return anything then it should not be a problem.

        [[snippet1]]<!DOCTYPE ...
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don&#39;t know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 18839
          • 39 Posts
          Thanks for the replies guys.

          I prefer to keep [[snippets]] or {{chunks}} on their own line to make it easier to read the code, but your suggestion worked like a charm dev_cw.

          Calling the snippet at the start of the chunk still produced the blank line.

          Heliotrope, your suggestion got me think about setting the placeholder with a plugin, so I came up with:

          //with checkbox for 'OnWebPageInit' ticked. 'OnWebPagePrerender' didn't seem to work.
          $e = &$modx->Event;
          switch($e->name) 
          {
              case 'OnWebPageInit':
                  $modx->setPlaceholder('templatePath', 'assets/templates/template_name/');
              break;
          }
          


          If you’re not into switches

          if ($e->name == 'OnWebPageInit')
          {
              $modx->setPlaceholder('templatePath', 'assets/templates/template_name/');
          }
          


          -------- or

          $modx->setPlaceholder('templatePath', 'assets/templates/template_name/');
          $mySampleChunk = $modx->getChunk('mySampleChunk');
          echo $mySampleChunk;
          


          Thanks for the feedback guys. So many ways to do something in MODx smiley, really shows what a powerful and flexible framework it is!