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

    It would be great in Revolution to have the ability of using Smarty syntax in templates.
      • 20413
      • 2,877 Posts
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        I know this is an old topic, but I wanted to weigh in: if statements in templates are troublesome. Beware.
          • 17499 ☆ A M B ☆
          • 872 Posts
          Quote from: Everett at Aug 23, 2010, 12:31 AM

          I know this is an old topic, but I wanted to weigh in: if statements in templates are troublesome. Beware.

          You mean with phx in Evo or with output filter in Revo ?
            • 9207 ☆ A M B ☆
            • 2,475 Posts
            I mean in general: you should not have to "debug" your View layer. I make no bones about it: I hate PHx. In principle, it can be extremely useful, but after cleaning up site after site that overused PHx, I realized that people will abuse if-statements in the View layer if its available to them. I hate debugging PHP in the view layer, but at least that’s a known entity -- I know HOW to debug it. My web server will cough up error messages with line numbers etc. But debugging nested PHx if-statements is just a painful waste of time because it’s flying completely blind. Can you find the matching backtick? Good luck.

            Revo’s implementation of View-level filters is sensible -- it lets you filter data in the "correct" way without the dangers of messy conditionals and loops in the view. I know Smarty can do a lot more things, but any time there are loops or if statements in the View layer, there will be problems.
              • 17499 ☆ A M B ☆
              • 872 Posts
              I kinda agree with you. I don’t like foreach statement, no, i don’t like php codes in my view ever since i use MODx.

              I did not use phx so much, but i like the basic if statement of the output filters in Revo, which can be useful in certain case.

              I tend to limit it for very simple case though.
              If my code needs more control, i would rather use a snippets with proper conditionnal statment end error management instead of imbricated/convoluted output filters.
                • 28215
                • 4,149 Posts
                Smarty syntax, and this level of conditional syntax, will never be built into the core of MODx. It violates the MODx core philosophy, and therefore will be rejected at each request.
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                  • 9207 ☆ A M B ☆
                  • 2,475 Posts
                  Smarty syntax, and this level of conditional syntax, will never be built into the core of MODx. It violates the MODx core philosophy, and therefore will be rejected at each request.

                  THANK YOU. That is why I want to have your babies. smiley
                    • 3634
                    • 19 Posts
                    /**
                    * Snippet code to use smarty for parsing chunks
                    **/
                    <?php
                    //check if any chunk name have been specified
                    if( !isset( $chunk ) ) return;

                    //load smarty
                    $modx->getService(’smarty’,’smarty.modSmarty’);

                    // check if resource is already registered
                    if( !function_exists( ’chunk_get_template’ ) )
                    {
                    function chunk_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
                    {
                    global $modx;
                    //read the template source from the chunk
                    $tpl_source = $modx->getChunk($tpl_name);
                    return true;
                    }

                    function chunk_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
                    {
                    //just assume the current time
                    //but you can keep record of times and serve them from a database eventualy
                    $tpl_timestamp = time();
                    return true;
                    }

                    function chunk_get_secure($tpl_name, &$smarty_obj)
                    {
                    //assume all templates are secure
                    //because they are created in the modX manager zone
                    return true;
                    }

                    function chunk_get_trusted($tpl_name, &$smarty_obj)
                    {
                    // not used for templates
                    }

                    // register the resource name "chunk"
                    $modx->smarty->register_resource("chunk", array("chunk_get_template",
                    "chunk_get_timestamp",
                    "chunk_get_secure",
                    "chunk_get_trusted"));
                    }

                    return $modx->smarty->fetch("chunk:$chunk");
                    ?>

                    Base on that, one could write a plugin to parse strings ( ’string:’ ) > documents onWebPage events wink