We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13610
    • 52 Posts
    Parse error: syntax error, unexpected $end in C:\Sites\Single3\xxxx\webroot\core\cache\elements\modsnippet\5.include.cache.php on line 32

    The code below works if I place the PHP in a SNIPPET and the HTML in a CHUCK and call them on the page.

    Why can’t I put HTML inside of a SNIPPET... I don’t want to have to
    $output .= "<HTML HEAR>";
    $output .= "MORE HTML";

    <?php
    
    // Process Registration
    if ($_POST['submit']) {
    	require_once('/lospen/dbconn.php'); 
    
    $vUsername = $_POST['username'];
    $vPassword = $_POST['password'];
    
    $vPasswordCrypt = crypt($vPassword, 'lospen123');
    
    	$InsertSQL = "INSERT into lospen_users (lpun_username, lpun_password) VALUES ('" . $vUsername . "', '" . $vPasswordCrypt .  "')";
     	mysql_select_db(DB_NAME, $link);
    	$result = mysql_query($InsertSQL) or die("DIDN'T WORK " .  mysql_error() . "<br>" . $InsertSQL);
    
    }
    // End Registration Process
    
    ?>
    <form name="frmReg" id="frmReg" action="[[~id]]" method="post">
    Username: <input type="text" name="username" id="username" /><br />
    Password:<input type="password" name="password" id="password" /><br />
    Confirm Password: <input type="password" name="cpassword" id="cpassword" /><br />
    <input type="submit" name="submit" id="submit" />
    
    </form>
    

    Thanks,

    Jason Buck
      Jason Buck
      • 17499 ☆ A M B ☆
      • 872 Posts
      You should use $output = ’your HTML’:

      It would allow your snippet to avoid those parse error without to much pain.
      Or just let your HTML into the containing chunk.
        • 22303 MODX Staff
        • 10,725 Posts
        Or you can make your snippet include a standard PHP file with code similar to the following and capture it’s output in an output buffer for return, e.g.:
        <?php
        ob_start();
        include MODX_CORE_PATH . "components/mycode/{$file}.php";
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
        ?>

        and call it like:
        [[MySnippet? &file=`myphpscript`<!-- other properties here -->]]
          • 13610
          • 52 Posts
          Thank you both for the weekend responses.

          I think I will run with Jason’s (OpenGeek’s) suggestion since I can now edit the .php files in MODX.

          I really do love the new version and I am trying to get up to speed on everything as the company I work for is in EVO and I am need to migrate that site soon... just so many custom SNIPPETS, and my security system is running off of SALESFORCE so I really need to get my head around how the REVO attribute based security works.

          Again, thanks for the weekend response.

          Jason Buck
          I ENDORSE MODX and look forward to a day when you guys are the #1 CMS in the opensource world.

          The best CMS system I have every used.

            Jason Buck
            • 14877
            • 110 Posts
            I notice nobody answered the poster’s actual question, "Why can’t I put HTML inside a snippet?". I suppose it doesn’t matter as he seemed happy to have suggestions as to how he could accomplish what he wanted.

            The reason is that the snippet tag [[snippetname-and-arguments]] is being replaced by the return value of the actual execution of the PHP code in the snippet, not by the PHP interpreter processing a file in the way it would if one surfed to a URL which was a PHP file. I have no idea how this is implemented (other than the snippets appear to be cached for execution), but that is what the documentation says happens.

            It is also a stylistic guideline not to put HTML in a snippet. This makes sense, especially if creating snippets that one is going to share. After all, the snippet writer doesn’t know how the end users are going to want to mark-up the content. So the snippet should be generating content, not marked-up content. Part of the MODx documentation explicitly discusses this separation in terms of implementing templates (i.e. chunks used as templates) to be used by snippets.

            Am I the only one in the dark? What are the functions: ob_start(), ob_get_contents() and ob_end_clean() huh
              __________________
              JRG
              • 3749
              • 24,544 Posts
              ob_start() creates an output buffer that captures any output that occurs.
              ob_get_contents() retrieved the content of the buffer to a PHP variable.
              ob_end_clean() empties the buffer and frees the memory it used.
                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
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                I don’t know about Revo, but with Evo you can have mixed PHP and HTML in snippets.

                One major disadvantage to this can be seen in Evo’s manager/action scripts; they are all mixed HTML and inline PHP which makes it impossible to modify the manager’s pages in the same way the documentObject can be manipulated in front-end pages. If the HTML were instead gathered into a variable as the documentObject is, then we wouldn’t need to use Javascript and DOM to manipulate the manager pages, as ManagerManager does for resource editing pages. This is one of the main reasons why Revo was begun in the first place.

                So while mixing HTML and inline PHP in a snippet works, it makes extending or modifying your snippet next to impossible without hacking its core into something else altogether.
                  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