Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Smarty 3.0 Alpha 1: Proof of Concept
Goto page Previous  1, 2, 3, 4, 5, 6, 7
 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
goper
Smarty Rookie


Joined: 24 Jul 2007
Posts: 5

PostPosted: Fri Nov 06, 2009 9:01 am    Post subject: Reply with quote

U.Tews wrote:
This was discussed already earlier.

For good reasons the final decission was NO.


Can you PM me, why is writing like that is bad?

U.Tews wrote:
Config files can now be loaded from the script on data and template objects.

$tpl = $smarty->createTemplate('mytpl.tpl'); // create template object
$tpl->config_load('my.conf'); // load config file


Is there a way to get config, without creating a template?
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 539

PostPosted: Tue Dec 01, 2009 6:09 pm    Post subject: Reply with quote

PHP/C style for loops are usually one of the most difficult things for non-programmers and novice programmers to learn. They often run into infinite loops and other problems.

I'm sure it's too late to mention this now, and it may be a totally stupid, but, since I just thought about it, I'll bring up the question anyway. Laughing What if the for loops were more Basic style?

I.e. simple syntax, no infinite loops.


Code:

{for $x = 0 to 5}
  HTML here
{/for}


Code:

{for $x = 5 to 0 step -1}
  HTML here
{/for}
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7274
Location: Lincoln Nebraska, USA

PostPosted: Tue Dec 01, 2009 9:52 pm    Post subject: Reply with quote

douglassdavis wrote:
PHP/C style for loops are usually one of the most difficult things for non-programmers and novice programmers to learn. They often run into infinite loops and other problems.

I'm sure it's too late to mention this now, and it may be a totally stupid, but, since I just thought about it, I'll bring up the question anyway. Laughing What if the for loops were more Basic style?

I.e. simple syntax, no infinite loops.


Code:

{for $x = 0 to 5}
  HTML here
{/for}


Code:

{for $x = 5 to 0 step -1}
  HTML here
{/for}


Great idea. Lets flesh this out. The new {foreach} syntax and this {for} syntax will be a welcome addition. The traditional for and foreach syntax will also be supported, but the simpler syntaxes will be outlined in the docs.

It does not forgo infinite loops, but it makes an easier read.
Back to top
View user's profile Send private message Visit poster's website
TakingSides
Smarty Rookie


Joined: 11 Dec 2010
Posts: 30

PostPosted: Wed Apr 27, 2011 2:57 pm    Post subject: Reply with quote

webtweakers wrote:
mohrt wrote:
jLix wrote:
Could it not be used for both?


Not really. The lexer doesn't know the assigned var type at compile time. It could check at runtime, but this adds another layer of complexity to the runtime logic. This also creates a level of ambiguity that could lend to difficult debugging when problems arise. Just use $foo.bar for arrays and $foo->bar for objects. simple. Smile


Hm.. I must say, I'm already happy that objects are being supported - this lifts Smarty up to modern development - so this seemingly minor issue should be something we can live with, right? Or wrong? I mean, I suppose a lot of templates are being designed by designers and not the back-end developers. These designers might not know if something is an object or an array and consequently don't know how to address it. Besides this, it would be nice to have a simple transparent method of addressing properties/methods on a variable without knowing the nitty gritty.

But I do understand your point of view completely (being a back-end developer myself). I'm sure there's an elegant and efficient way to solve this. Smile


I would like to say that the way PHP handles objects and arrays, i find perfect.

I understand your point with designers not knowing the difference. But 1 character less, and not really prittier at all.

But i am a strong believer that when you build a website/application you use smarty solely for templates, this means there should be as little dynamic code within the template as possible, keep the code as basic/minimal as possible. use lots of plugins/modifiers where necessary and fully document your overall acheivements then your designers will know if its an object or a variable. Designers shouldn't really have to touch the Smarty code, except from moving elements around the design, that's what templates are.

Templates are not a nicer looking php page, they are a structure of code used to separate the model logic from the view logic, even if you don't quite have an MVC infrastructure.

for instance you can have 3 templates to run your entire website. for instance:

header, footer (standard across all templates? make as includes to reduce code), 3 column page is template #1, 2 column page is template #2 and 4 column page is template #3. its trhe developers duty to correctly assign all website widgets data and information using plugins, modifiers and simple loops so designers only need to move a one line tag with properties to get things working.

for instance:

template_1.tpl
Code:

<!DOCTYPE html>
<html>

    <head>
        {include file='inc/head.tpl'}
    </head>
    <body>
   
        {include file='inc/header.tpl'}

        <div id="leftBox">
            {menu}
            {quick_search}
            {adverts show=$advertNum|default:'3'}
        </div>

        <div id="rightBox"> <!-- See explanations below --> </div>
       
        {include file='inc/footer.tpl'}

    </body>
</html>



Explanations...

Method #1
Code:
You can then place the following into your template:

<div id="rightBox"> {$yourPageContent} </div>

Then inside your php document write...

$smarty->assign('yourPageContent', $smarty->fetch('home.tpl'));


Method #2
Code:
You can use the very powerful pre-compile filter...

<div id="rightBox"> <smarty:object name="home" /> </div>

then do...

$smarty->registerFilter(Smarty::FILTER_PRE, 'precompile_filter_language');

with...

function precompile_filter_language($tplHTML) {
    $out = array();
    preg_match_all('~(<smarty:object name="(.*?)" />)~iU', $tplHTML, $out);

    // then foreach tag, simply do something like... iterate through all smarty:object tags
    foreach ($out as $tag) {
        $xml = new SimpleXMLElement($tag[0]); // index probs wrong, but only need tweaking
        $tplHTML = str_ireplace($tag[0], $smarty->fetch($xml->name . '.tpl'), $tplHTML);
    }

    return $tplHTML;
}


Basically, keeping your template as a template, which is re-usable but the content can be completely different for the same template across a number of pages.

Above is a basic TEMPLATE. the idea is you can use this template for every page of your website, and change the body content, with two methods
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7
Page 7 of 7

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP