We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38060
    • 29 Posts
    I see in some snippets, that they use mustaches {} when including files. Like in the last line of the code below:

    $wayfinder_base = $modx->config['base_path']."assets/snippets/wayfinder/";
    
    //Include a custom config file if specified
    $config = (isset($config)) ? "{$wayfinder_base}configs/{$config}.config.php" : "{$wayfinder_base}configs/default.config.php";
    if (file_exists($config)) {
    	include("$config");
    }
    
    include_once("{$wayfinder_base}wayfinder.inc.php");


    Wouldn't this work without these mustaches? Like this:

    include_once($wayfinder_base."wayfinder.inc.php");


    I copied the mustache technique for my own snippets, but I actually want to understand what is going on there.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      In some cases with simple variables it will work without, but in the case of more complex variables they are necessary. So some programmers just get into the habit of always using them.
        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
        • 38060
        • 29 Posts
        Quote from: sottwell at Oct 24, 2013, 02:05 PM
        In some cases with simple variables it will work without, but in the case of more complex variables they are necessary. So some programmers just get into the habit of always using them.

        Thank you this is a good explanation.

        Now I get it: without the variable would read $wayfinder_basewayfinder, and $wayfinder_basewayfinder is of course empty. So I guess both ways are right.

        Very interesting: the mustaches are not rendered as part of the string.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          This is an interesting page to read over http://php.net/manual/en/language.types.string.php
            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