Results 1 to 5 of 5

Thread: smarty

  1. #1
    New user
    Join Date
    04-11-10.
    Location
    France
    Posts
    4

    Default smarty

    Hi everyone,

    With smarty extension you can write your templates easier.
    - To begin, i suggest you the use of those delimiters : {= for left and ;} for right

    - For exemple, the template tl_article could be wrote like this :
    - In smarty debug mode you'll have all variables assigned for each template loaded.
    - Smarty give you an easier way to manage loops, sections, and much more ... and an easier language for your team.

    :arrow: This extension is not actually in stable status, because it need to be tested in several environnement, so leave me your feedbacks, and i'll do my best for evolving it !

  2. #2
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: smarty

    Hi there,

    This looks interesting.

    I was wondering if you had any insight on if/how Smarty affects server load and page load times.

    I've heard conflicting things on this -- what's your point of view?

    Thanks!
    Brian

  3. #3
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Re: smarty

    After posting this I realized this is an extension, an optional addition to Contao. Perhaps my comments are correct, but not placed in the right context. If you feel I am completely wrong here, please accept my apologies. Below is my original message ops:

    I've had a discussion in another forum about another templating engine Tiny But Strong (TBS). The subject was why no templating engine was used for that project. I was convinced TBS would be a great templating engine for a system that had none. It was pointed out to me that template engines must separate business logic from the presentation of that data and that can be done without a new template language. PHP can be one on its own.

    Contao addressed the templating side by restricting available options in each template and also using the shorthand and alternative php structure names (for example: foreach () ... endforeach. This is in no real way harder to learn then Smarties syntax that uses the PHP grammar anyway.

    Interesting article: http://www.massassi.com/php/articles/template_engines/
    Quick summary: Adding Smarty does not add new functionality besides from caching. What Smarty does is adding shortend tags for php functions: {= is equal to <?php or <?php echo, and ;} to various closing tags. Adding Smarty means the file has to be parsed by Smarty first, evaluated and built again, except it takes more time and memory then without. Smarty is a way of displaying the same information in the same structure, the same way with different symbols.

    I apologize for appearing so negative regarding your extension. I didn't mean to offend you and hope you don't take it that way. I do like someone took the effort of integrating Smarty, people may have a need for it even though I cannot agree. I also did not look at the quality of the code which might even be excellent. Thanks for adding the extension!

  4. #4
    New user
    Join Date
    04-11-10.
    Location
    France
    Posts
    4

    Default Re: smarty

    I've heard conflicting things on this -- what's your point of view?
    Hi Medianomaly,

    I've heard it too, but i often use this library for personnal et business projects, and for me the loading time is insignificant. Moreover, smarty make temp files of compiled template, and use the temp file if nothing has changed on it !

    You will especially save your time on coding custom template, because the logical of this language is more oriented to the frontend. Just try it ...

  5. #5
    New user
    Join Date
    04-11-10.
    Location
    France
    Posts
    4

    Default Re: smarty

    Smarty is a way of displaying the same information in the same structure, the same way with different symbols.
    Hi Ruud,

    Yes you're partialy right but .... not exactly !

    I take a loop in php template language :
    Code:
    <?php $i = 0; ?>
    <?php foreach($articles as $article):  $i++; ?>
    <div class="article<?php if($i==1): ?> first<?php endif; ?><?php if($i==count($articles)): ?> last<?php endif; ?>">
    <?php echo $article; ?>
    </div>
    <?php endforeach; ?>
    In smarty, this will be :
    Code:
    {=foreach from=$articles item=article name=loop_article;}
    <div class="article{=if $smarty.foreach.loop_article.first;} first{=/if;}{=if $smarty.foreach.loop_article.last;} last{=/if;}">
    {=$article;}
    </div>
    {=/foreach;}
    This is not very shorter, but more comprehensive by non developpers people ! Here you have a simple case, but in complex case, i think it's great to think frontend , and not technical way to do a thing. Like here, putting a var to 0 to increment it, for determinating the first and last element of the loop !

    Smarty have a lot of shortcut like this ..... but this tool is a choice !

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •