We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20289
    • 958 Posts
    I am not against Smarty or any templating system that makes life easier!, I simply like the code jungle!
    Fair enough with what Stefan presents as an Smarty way of templating, it sure saves much time and effort!
      [img]http://i10.tinypic.com/52c4eir.gif[/img][/td]
      [td][Wiki] [Persian support forum]
      [SVN] [RTL SVN Branch] [bugs] [FishEye+Crucible] [Learn MODx!] | [My Google Code]
      [font=tahoma][برای دسترسی به راهنمای فارسی به [url=http://www.modxcms.ir]
      • 28436
      • 242 Posts
      hallo Taff,

      after spending much too long messing around with a modified xt:commerce template.

      yes, good idea:

      for example the mail_order.txt, the goal is a personal salutation. Normaly you have no chance to get the customer_firstname, customer_gender oder customer_lastname without hacking the send_order.php

      but.... build a smarty function like this

      function.user_info.php
      <?php
      function smarty_function_user_info( $params, &$smarty )
      {
          global $modx;
          if( isset( $_SESSION['customer_id']) && !empty( $_SESSION['customer_id'] ) )
          {
              $customer_id = $_SESSION['customer_id'];
          	$sql ='
      	        SELECT 
      	            *
      	        FROM
      	            `customers` as k,
      	            `address_book` as a
      	        WHERE
      	            k.`customers_id` = \''.$customer_id.'\'
      	        AND 
      	            a.`customers_id` = k.`customers_id`
      	        AND
      	            a.`address_book_id` = k.`customers_default_address_id` 
      	    ';
      	    
      	    $info = $modx->db->getRow( $modx->db->query( $sql ) );
      	    $felder = explode(',',$params['felder']);
      	    foreach( $felder as $feld )
      	    {
      	        $smarty->assign($feld,$info[$feld]);
      	    }
      	    return null;
          }
          else
          {
              return null;
          }
      }
      ?>


      then in the templaate

      {user_info felder='customer_gender,customer_firstname,customer_lastame'}
      Dear {if $customer_gender=='f'}Ms.{else}Mr.{/if} {$customer_firstname} {$customer_lastname}


      oh yes, i love it smiley ok, its enough, i’ll be quiet.

      ciao, Stefan
      • People keep in mind this is JUST for the manager. It doesn’t force you into using Smarty on the front end. It also doesn’t preclude you from building your own native template system driven version of the manager. In fact I’d bet that someone does a jQuery/native-MODx manager given the frequent calls for that. This will be much more straightforward to do in 097+.

        We chose ExtJS + Smarty because it accelerates the development time tremendously and as illustrated in the code example above we don’t have to worry about the template logic. Smarty’s been around for a long time and is heavily proven and offers a lot of robust templating options... and I repeat this is JUST for the manager.
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 28215
          • 4,149 Posts
          As someone who’s been in web development in PHP since PHP 2/FI, I’ve seen a lot of templating systems come and go. I’ve seen Smarty since it started.

          That said, I have noticed a lot of people who are vehemently opposed to Smarty. My personal experience with those people is that they have:
          A) Used smarty in a dev environment where it was not deployed properly
          B) Never used smarty (or used it very little) but have relied on others’ opinions to form their beliefs.

          That said, Smarty will be in 0.9.7’s default manager template. And that’s about it. Like Ryan has said, the front-end does not use Smarty, nor would any custom manager template you build have to include it. The reasons we chose it were:

          1) Quick and easy to learn
          2) Exposure of objects ($user->name in PHP is easily accessible as {$user->name} in Smarty)
          3) Easy placeholder variable assigning
          4) Complete and proper View/Controller separation for MVC2 design

          And even with all of that, for those of you who haven’t even looked at 0.9.7, you might want to. Most of 0.9.7 is actually built with straight ExtJS 2.0, which bases most of its data off of Javascript and JSON. Smarty plays a very minimal role.

          If you’re against Smarty, no one is stopping you from creating a manager template without it. However, we as the dev team have decided to go the route of Smarty for the 0.9.7 release.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 16429
            • 254 Posts
            MMm... the discussion here has taken a shape I don’t think it’s the right way to discuss this thing.

            When I’ve cryed hearing of Smarty I’ve specified that we yet have a templating system, that we yet know how it works (and, sincerely, we like it at 100%) and we are yet able to insert logic in it.

            I think that’s the key point. If Smarty is so good, why it’s not Smarty the template engine of MODx? With the born of PHx I felt I didn’t need more power. All the power we need (and a very simple way to control it) it’s in our hands, yet.

            Quote from: stefan at Apr 19, 2008, 09:38 AM

            hey folks

            why against smarty? its one of the world finest stuff... give it a serious try and you will love it.

            nice plugin|modifier-system {$pagetitle|replace:&:&amp;}
            direct access to post,get,session values {if smarty.session.login}you Logged in{/if}
            PHx does that, and you can extend it, and you can use it in templates. Don’t need Smarty for that.
            Quote from: stefan at Apr 19, 2008, 09:38 AM

            loop arrays in Template {foreach} do loop {/foreach}
            run "inline-php" code {php}echo ’hello world’; {/php}
            I think you want to mix presentation and logic too much. Go for snippets to do that kind of things or you’ll find yourself in serious trouble when you want to update a site with 10+ templates, 30+ chunks, et cetera. Just an advice!
            Quote from: stefan at Apr 19, 2008, 09:38 AM

            nice caching functions.... and many more...


            I use smarty for my own snippets because i havent the power to create such a template-parser and sometimes i wish all of you guys/and girls use smarty for your snippets as well. Same base for all. Sorry, but all this selfmade stuff around is not able to fight/beat smarty.
            [...]
            As I’ve highlighted with bold font, you’re right, same base for all. You’re using Smarty to achieve results you can achieve with the normal template+PHx, probably because you’re accustomed to follow programming patterns which includes the use of Smarty, and you find it quicker and simpler just because you’re used to.
            But... if you say "same base for all", you’re wrong. We use the same base for all. You aren’t using the same base as all. Perhaps, you meant "Same base as me". Well, no offence, but we are not those that take another road while the rest of us goes the normal road.

            I’m not into programming as I think I’ve to be to strongly motivate why the inclusion of Smarty is not a good idea. But, sorry, no word you can write or tell can convince me you’ve not reinvented the wheel with this choice. Well, reinventing no, but... now we have 2 kinds of wheel, both circular, both rolling... Still two wheels, when we need one.
            Ryan has told this way the devs saved a lot of time not needing to code another template system. Well! ok! Use the DocumentParser class! It works for the frontend, why don’t use it for the backend definitely? Aren’t we doing the same to manage Users in MODx? Same logic, a simple sign ("-") does the difference.
            Re-use, re-use, re-use...

            I feel to be very near to the truth if I tell you those who said "+n against Smarty" were meaning "we don’t need Smarty" and not "Smarty is crap" (which, btw, is what you’re now debating here and is largely off topic if you think about smiley ).

            Just my 2 cents (perhaps, less)

              kudo
              www.kudolink.com - webdesign (surprised?)

              [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
              • 28436
              • 242 Posts
              Hello kudolink

              When I’ve cryed hearing of Smarty I’ve specified that we yet have a templating system, that we yet know how it works (and, sincerely, we like it at 100%) and we are yet able to insert logic in it.

              Yes, you are right! We already have modx as our base. And that’s great.

              I think that’s the key point. If Smarty is so good, why it’s not Smarty the template engine of MODx? With the born of PHx I felt I didn’t need more power. All the power we need (and a very simple way to control it) it’s in our hands, yet.
              I think the key point is: whats the best for my requirements.
              PHx does that, and you can extend it, and you can use it in templates. Don’t need Smarty for that.
              phx is far away from smarty... jesus.. i won’t jugde anything... i use and love phx...
              I think you want to mix presentation and logic too much. Go for snippets to do that kind of things or......
              Of course, always the best way is doing what is necessary to fight the job.
              Running code from the template is exactly the point why phx is so usefull.
              [*table_data:html_table*]
              use the smarty-modifier html_table for your phx ... wonderful or
              [+phx:if=`2`:is=`3`:then=`this will never happen...`:else=`...so there is no need for this condition`+]
              This looks like mixed present/func as well. This question is not depending on certain software.
              ... you’ll find yourself in serious trouble when you want to update a site with 10+ templates, 30+ chunks, et cetera. Just an advice!
              No. You made your templates and you have to know whats going on with them. And so you keep out of trouble. This is a rule concerning nearly every point in a human life. The real serious trouble in what i am stuck is that my english is not stable enough( currently dev-r2) to explain in proper words what i want to say.
              But... if you say "same base for all", you’re wrong. We use the same base for all. You aren’t using the same base as all. Perhaps, you meant "Same base as me". Well, no offence, but we are not those that take another road while the rest of us goes the normal road.
              Your right. This was ambiguous. It was more a wish as an order. We are all happy about the pear-archive and the js-libs and all the other great libs that make our all live easier. If this is a fact, then we are happy about the "Same base for all". This is what i mean.
              Re-use, re-use, re-use...
              yes yes yes but what is easier to re-use and maintain and share(at first the knowledge about it)?. A "same base" or a "individual base"? What do you think?

              those who said "+n against Smarty" were meaning "we don’t need Smarty" and not "Smarty is crap"
              Yes right and i don’t read that. My intention was not proselyte anyone or dogmatize anything... iam the a friend of a free world.
              i won’t provoke anyone. i just want say:"take a look to it and after you find out whats going on with it, you will love it. It shows its sex appeal at the second or a later view". .... Thats exactly the words which i say to modx-beginners.... That’s all. No War. I am not able to explain by words, so i thought: give them a "getting started" example.

              Just my 2 cents (perhaps, less)
              thank you and have a nice time.
              tschüß, Stefan
              • I may be speaking out of turn here (since I am not a dev with only a brief read on Smarty) but MODx uses a proprietary templating engine (very similar in syntax to smartys placeholder classes) that has been extended by PHx.

                Arguments aside for the benefits of backward compatibility and not changing to another templating engine, the benefit of using an OpenSource, freely available and external system is that development on MODx can focus the system/framework core, not on the DB layer (xPDO) not on the templating engine (smarty). In addition, the team can bring in outside devs and designers with experience in Smarty and not have to learn a new system. It becomes an inherent standard. Sure the current system is nice and if it weren’t for the need to continually improve MODx it could freeze at 0.9.6 and that be that.

                I think that with limits and issue an external engine will be outweigh any brought on by the ease, documentation and support of a popular (yet controversial) system.

                Finally, as has been pointed out, one could use php and the MODx API to build templates, map to custom function libraries and classes or another engine alltogether. Heck, you could even do that now if you wanted (why I am not sure).
                  Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. BlogTwitterLinkedInGitHub
                  • 6726
                  • 7,075 Posts
                  And also as Shaun reminded us above, keep in mind we’re talking about the manager’s template.

                  Right now there is no template system for the manager and you have to hack your way into modifying it. In the future if you need to customize the manager it’ll way easier ! Get 0.9.7, browse the manager templates and compare with the existing 0.9.6 templates, you’ll see. I mean I am no Smarty expert and I am making sense out of it smiley

                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l&#39;outil id
                    • 16429
                    • 254 Posts
                    (@davidm: I’ll love to give it a try but I don’t know where I can download the branch)

                    I’m very surprised, I can’t understand at all laugh

                    This is what I see here:
                    we have a templating system we trust, devs work on it, we bet on it to do the critical work of presenting pages to users and spiders.
                    On the other hand, we insert into MODx another template engine because... well, the main argument here is "devs don’t need to focus on the template engine for the manager".
                    I still don’t see the point guys, the templating system is there now, it works, and working on it means strenghtening it and not loosing time!
                    When you say "you can even use the MODx templating sys, if you want", I still think the right sentence is viceversa: "You can even use Smarty, if you want".
                    Sincerely I don’t know my thoughts now: if the devs want to use Smarty, maybe I can think the DocumentParser is not that good.
                    But in this case, it’s not better to use Smarty at all?

                    Do you understand what I mean? It’s the approach to this decision that has a hole in its pattern. Or it’s good the DocumentParser, or Smarty. Can’t be either! They do the same identical thing! Do you realize it?
                    I can’t believe the same devs that created MODx aren’t able to productively re-use their code and are taking another engine to do the same thing their code has been written to do.

                    I don’t want to upset no one, I fully respect the devs and I don’t want to raise a chorus of "hey boy, we are the devs and you don’t develop the core so speak about your little snippets and take the core as we give it", but I’ve seen in MODx a new concept of CMS/CMF when I found it. MODx meant new solutions, new answers for old questions.

                    And now I read "we will use Smarty to render the manager". But Smarty is one of the OLD answers sad. And it’s something we don’t have control on. What about Smarty upgrades? Will we have to keep 2 softwares updated and secured? Will you drop a MODx update everytime Smarty updates?
                    Will we need to learn to use Smarty to make a little modification of the manager (and only for that)?

                    Ok. Now we use Smarty for the backend because the devs don’t need to loose work. Tomorrow? We’ll switch to Smarty even for the frontend? I’m pretty sure, now. If it is loose work on the backend, it will even on the frontend.
                    If not, it will be a contradiction.

                    Wanna loose less time? Don’t play with Ext which looks cool but is absolutely not necessary. First because you’ve to arrange all the manager with it’s syntax and second because the more JS you add in the manager, the less we can customize it.
                    Better: completely strip out the JS from the manager. Live only the minimum to have the right click menu on the DocTree and the DocumentDirty function.
                    We all have lived for years without ajax and modal windows. Use CSS which is light and fast and extremely customizable, and go for a full page refresh. No one will cry because the menu has been refreshed with the page, nor the document tree.
                    Striping out the frames is the better thing you can do, and probably it’s the bigger step available.

                    -------

                    I write all this things about this question not because I’m against Smarty (well, sincerely if I prefered Smarty I’d have picked a Smarty powered CMF, and not MODx, but...) but because this can be a precedent. If improving such a big piece of MODx is loose time, why developing MODx templating sys is not loose time? Or the entire MODx! There are other OOP MVC CMF around. They use Smarty.
                    Instead of moving away from other CMFs to be the best one, are we going towards those?
                      kudo
                      www.kudolink.com - webdesign (surprised?)

                      [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
                    • Kudolink, I think you’re entirely flawed in your understanding of both the process that went into the decision and the reasons for doing so, and there’s certainly no argument that you’ll be able to make to change the manager implementation that will ship with 097. You might as well start arguing for getting rid of PHP and port to Ruby, since PHP is so old school and Ruby is the shiny new kid on the block.

                      Smarty has nothing to do with the document parser. Smarty is a templating implementation; with PHx you can emulate some of the behaviors found in Smarty, but certainly not all. PHx in it’s current form can also cause a lot of problems since it traps the parser and changes things. PHx can kill your site actually. This personally happened to me within the last 12 hours.

                      If you are worried about modifying the manager, you better learn ExtJS first as that learning curve is probably 10-20x that of Smarty; Smarty is very sparingly used in the Manager, exactly as Shaun stated earlier. Does our use of ExtJS on the back end in 097 or Mootools in 096 mean that that’s all you can use on the front end? Nope ... not one bit and in fact some of the coolest MODx sites I’ve seen use jQuery. Ditto that for the template methods in 097.

                      When you create your own version of the manager, you can choose whatever technology you’d like. In fact we welcome and hope there will be a variety of alternate implementations from the community. smiley
                        Ryan Thrash, MODX Co-Founder
                        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me