We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Hey Charlie, can you show an example of h2o templating here?
      Ryan Thrash, MODX Co-Founder
      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
      • 33337
      • 3,975 Posts
      I would like to see h2o example too. smiley
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 34017
        • 898 Posts
        The basis is like any template class.

        // Controller:
           $data['user'] = $model->getUser();
           $data['comments'] = $model->getAllComments();
        
           $tpl = new h2o('comments.tpl');
           $tpl->render($data);
        


        // comments.tpl
        {% for comment in comments %}
           {% if user = "admin" %}
            <div class="comments by-admin"
           {% else %}
             <div class="comments">
           {% endif %}
        
            Comments go here.....
            </div>
        {% endfor %}
        


        That’s a really simple example. What I like about it:
        - no need for inner and outer chunks
        - it’s got PHx like modifiers (or smarty-like if you will)
        - i think the django syntax is really really clean
        - This is really for designers who know some html but php scares the hell out of them. (I am starting to like plain php/helper functions in my view, but alas)
          Chuck the Trukk
          ProWebscape.com :: Nashville-WebDesign.com
          - - - - - - - -
          What are TV's? Here's some info below.
          http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
          http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
        • My point is, Smarty and h20 already exist, so use them if that’s how you want to build web sites. MODx avoids this for very specific reasons, and adding all of that functionality back into the core would destroy the parsing performance, since it was built to avoid these combinations of logic and presentation. TBH, you might as well use plain PHP, or JSP, or ASP if you want to circumvent this important MVC goal.
          • Indeed, just before I discovered MODx, I was working through a very interesting tutorial on building a site management and templating system using only <?php include ’whatever’; ?> tags for everything. Very simple, very quick. But MODx served my purposes much better, as I didn’t feel confidant in using that system to build my own CMS. Besides which, a properly configured database is much more efficient than PHP working with the filesystem.
              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
            • Then again, that is the beauty of MODx. It doesn’t force anything or restrict you from using convenient things in select areas like PHx if conditionals if you want to be bad. tongue The wealth of flexible third-party add-ons make for some pretty compelling reasons to stay within MODx as opposed to rolling it all from scratch. Heck, even Revo has the PHx filters in the parser core doesn’t it?
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 16183
                • 1,390 Posts
                Quote from: rthrash at Aug 15, 2009, 07:50 PM

                Heck, even Revo has the PHx filters in the parser core doesn’t it?

                Yep it does according to this. Haven’t been able to find examples of conditional statements though (specifically if...else...elseif)..

                cheers/k
                  • 3749
                  • 24,544 Posts
                  Quote from: kongondo at Aug 15, 2009, 08:15 PM

                  Quote from: rthrash at Aug 15, 2009, 07:50 PM

                  Heck, even Revo has the PHx filters in the parser core doesn’t it?

                  Yep it does according to this. Haven’t been able to find examples of conditional statements though (specifically if...else...elseif)..
                  cheers/k

                  There’s no elseif that I’m aware of. I think the conditional examples are missing because it’s much better (and almost as easy) to use a snippet.

                  That said, here are a few examples (from the book wink):

                  [[*createdby:userinfo=`username`:is=`admin`:then=`Admin did this`:else=`Someone else did it`]]
                  
                  [[++SettingName:is=`1`:then=`[[$YesChunk]]`:else=`[[$NoChunk`]]
                  
                  [[++SettingName:is=`1`:then=`[[MySnippet]]`:else=``]]
                  
                  [[$Text:len:isgte=`10`:and:islte=`40`:then=`[[$Text]]`:else=`Out of Range`]]
                    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
                    • 16183
                    • 1,390 Posts
                    Thx for the clarification Bob. I have "something" in the works and needed to know this.

                    :)

                    cheers/k
                      • 3749
                      • 24,544 Posts
                      Quote from: kongondo at Aug 15, 2009, 08:27 PM

                      Thx for the clarification Bob. I have "something" in the works and needed to know this.

                      :)

                      cheers/k

                      Hmmm . . . let me guess. wink
                        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