Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty 3.0 Alpha 1: Proof of Concept
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
kiboke
Smarty n00b


Joined: 20 Oct 2008
Posts: 2

PostPosted: Mon Oct 20, 2008 1:57 pm    Post subject: Reply with quote

mohrt wrote:
You will have {for ...} directly available in the template.


No, that wasn't my point Smile I think smarty should run faster internally if possible, including plugins.

And yes of course i'm going to enjoy using {for...} despite smarty's internal optimization Smile
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Oct 20, 2008 2:01 pm    Post subject: Reply with quote

Optimization is always good. All of the code will be available to dissect. You can submit ideas and patches right here to the forum. We probably won't focus too much on optimization until everything is functional.
Back to top
View user's profile Send private message Visit poster's website
Shadzik
Smarty Rookie


Joined: 01 Aug 2007
Posts: 5

PostPosted: Mon Oct 20, 2008 5:32 pm    Post subject: Reply with quote

mohrt wrote:
Shadzik wrote:
Do you think about php5.3, Unicode and Namespace ? It could resolve some problems. Like extracting array to single variables in PHP-style Templates.

It's nice, but way too new. After PHP 6 is mainstream it may be possible to rely on these features.

I don't think namespace is too new. Now is new but in about 1 month there is plan to release stable version of PHP5.3 if not now then sure at the end of the year.
If Smarty 3 is in Proof Concept You should really think about this. If You will wait for PHP6 than i think You will not implement it then. Then you will say it is for compatibility with earlier versions. And smarty 3 won't be build in 1-2 months. You will have enough time to test it. And i will with pleasure test it or even help with this project Smile
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Oct 20, 2008 9:51 pm    Post subject: Reply with quote

I don't want to rely on 5.3 features until it has a decent userbase. At this point 5.1 is probably OK to rely on, but 5.3 is way too soon. It will take some time. Name spaces may be incorporated into Smarty at a future date.
Back to top
View user's profile Send private message Visit poster's website
Shadzik
Smarty Rookie


Joined: 01 Aug 2007
Posts: 5

PostPosted: Tue Oct 21, 2008 6:33 am    Post subject: Reply with quote

I have a question, if i made a patch, what to do with it ? where to send it ?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Oct 21, 2008 6:48 am    Post subject: Reply with quote

For the moment please send your suggestions and patches here.

Currently many things are still experimental and we are trying things out. As mohrt said already things are not optimized at the moment and may change a bit from day to day.

But any input is wellcome.
Back to top
View user's profile Send private message
Shadzik
Smarty Rookie


Joined: 01 Aug 2007
Posts: 5

PostPosted: Tue Oct 21, 2008 7:03 am    Post subject: Reply with quote

i don't like that type of singleton. I'm working with framework that is not small and i don't know if there is created Smarty object or not so i always use instance and this one need to start object in classic way
Code:
$smarty = New Smarty();

and then Smarty::instance(); work
And i'm using such thing if there is no Object then it is created
Code:
public static function instance() {
    static $instance = null;
    if ( $instance === null ) {
        $instance = New Smarty();
    }
    return $instance;
}

Sorry this code above will not work with this Smarty. Constructor run other object that require Smarty object an cod is looping

And
one thing if you are not using autoload from php then when you check class for existence, use second parameter with value 'false' that no autoload will be executed.
Code:
Index: internal.modifier.php
===================================================================
--- internal.modifier.php       (revision 2928)
+++ internal.modifier.php       (working copy)
@@ -26,7 +26,7 @@
       if (!isset($objects[$class_name]))
       {

-          if(class_exists($class_name) || $this->smarty->loadPlugin($class_name))
+          if(class_exists($class_name, false) || $this->smarty->loadPlugin($class_name))
           {
               // use plugin if found
               $objects[$class_name] = new $class_name;


Code:
Index: libs/Smarty.class.php                                                             
===================================================================                     
--- libs/Smarty.class.php       (revision 2928)                                         
+++ libs/Smarty.class.php       (working copy)                                           
@@ -224,7 +225,7 @@
     public function loadPlugin($class_name)
     {
         // if class exists, exit silently (already loaded)
-        if (class_exists($class_name))
+        if (class_exists($class_name, false ))
             return true;
         // Plugin name is expected to be: Smarty_[Type]_[Name]
         $class_name = strtolower($class_name);
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Oct 21, 2008 1:56 pm    Post subject: Reply with quote

class_exists() checks are fixed in SVN.

As for the instance, you will need to check that yourself:

Code:
if(!$smarty = smarty::instance())
  $smarty = new Smarty();


I suppose we could make this work so the instance can initialize, but ideally you would be creating the Smarty instance somewhere early in your code and do all the initializing that needs to be done.
Back to top
View user's profile Send private message Visit poster's website
Spuerhund
Smarty Rookie


Joined: 20 Jan 2005
Posts: 16

PostPosted: Tue Oct 21, 2008 2:59 pm    Post subject: Reply with quote

Another improvement i would like to see in Smarty 3 is non-functional. PLEASE use the auto code formatting that your IDE offers. Reading Smarty 2.x code is a pain sometimes.

In Eclipse you just have to push Ctrl+Shift+F iirc, in Netbeans the default shortcut is Alt+Shift+F or something like that. Do so before every SVN check in. Thanks in advance.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Oct 21, 2008 3:35 pm    Post subject: Reply with quote

Spuerhund wrote:
Another improvement i would like to see in Smarty 3 is non-functional. PLEASE use the auto code formatting that your IDE offers. Reading Smarty 2.x code is a pain sometimes.

In Eclipse you just have to push Ctrl+Shift+F iirc, in Netbeans the default shortcut is Alt+Shift+F or something like that. Do so before every SVN check in. Thanks in advance.


I think we have decided to follow the PEAR coding standards. Using UNIX line breaks is a given. Is that what you are referring to?
Back to top
View user's profile Send private message Visit poster's website
Spuerhund
Smarty Rookie


Joined: 20 Jan 2005
Posts: 16

PostPosted: Wed Oct 22, 2008 9:19 am    Post subject: Reply with quote

I will give some examples to demonstrate what i mean. I just took the first that i could find, but i am sure there are plenty of other cases which are even worse. They could all be solved by using auto code formatting.

Example 1: whitespace after "," or not? Single or double quotes for default argument values?

file: plugins/modifier.indent.php
Code:
function smarty_modifier_indent($string,$chars=4,$char=" ")

file: plugins/modifier.escape.php
Code:
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = 'ISO-8859-1')


Example 2: whitespaces between braces and expressions or not?

file: Config_File.class.php
Quote:
if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {

Quote:
if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {


Example 3: if-statement must use braces?

file: Smarty_Compiler.class.php
Quote:
if (substr($template_tag, 0, 1) == '*' && substr($template_tag, -1) == '*')
return '';

Code:
 if (empty($attrs['file'])) {
            $this->_syntax_error("missing 'file' attribute in include tag", E_USER_ERROR, __FILE__, __LINE__);
        }
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Oct 22, 2008 2:48 pm    Post subject: Reply with quote

I see. Yes we are conforming to the PEAR code formatting, so I'm not sure if "auto code format" will do what we want in everyone's IDEs.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


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

PostPosted: Wed Oct 22, 2008 2:59 pm    Post subject: Reply with quote

Some interesting things happening in alpha lately.

First, we are proposing to deprecate both {section} and {foreach} in favor of a new {for} function for looping. Examples:

Code:
{for $var in $myarray}
    key is {$var:key}
    index is {$var:index}
    iteration is {$var:iteration}
    total is {$var:total}
{/for}


Notice we use {$var:foo} to access array properties, and the iteration var is used as the identifier (no need to "name" a for loop.)

Another example:

Code:
{for $x=0; $x<100; $x++}
   {$myarray[$x]}
{/for}


This is the way to loop over multiple variables.

The dot "." is still going to be used for array access, since the syntax is highly favored by template designers. However, PHP-style array access is also permissible:

Code:
{$foo.bar.baz}
{$foo['bar']['baz']}


Both of the above are identical.

Since the dot "." is used for array access, catenation will be done with the "&" symbol:

Code:
{$foo & $bar}


And yes, spaces will be allowed in tag syntax too, so this is fine:

Code:
{$foo . bar . blah}
{$foo | escape}
Back to top
View user's profile Send private message Visit poster's website
conner_bw
Smarty Rookie


Joined: 21 Dec 2007
Posts: 17

PostPosted: Thu Oct 23, 2008 9:45 pm    Post subject: Reply with quote

Hi, please look at my project sux0r.org which wraps and extends Smarty and SmartyValidate classes. I'm a fan of Smarty, I use it everyday, so don't take the following 2 suggestions as flamebait, but rather constructive criticism.

1. Location of templates, templates_c, and cache are in the wrong place.

Separating business logic from template logic in the real world means keep the designers out of the code that actually does real work.

Currently, Smarty encourages coders to put their templates in a subdirectory of the code. That's fine for the coder, saves time, in not clicking around looking for templates. But when it comes to working with a team, on large projects, this means designers are mucking around in the same directories structure as the coder. Also setting permissions on templates_c and cache on a per directory basis.

In sux0r, I look for Smarty templates in two places. First, in a directory called templates located off the root, and if I can't find it there I cascade down and look in the subdirectory i.e. how it is now. Furthermore, templates_c and cache are also moved to subdirectories in a separate temporary directory. Making it easier to manage permissions and not mess up CVS/SVN with a bunch of individual .ignore lists.

Of course, the fact that I was able to do this with Smarty in the first place is a good thing. It shows that it's very flexible. The fact that it's not the default is counter-intuitive.

2) Renderer objects, not "plug-ins"

A few months ago I stumbled on a suggestion in this forum for object notation in Smarty. I figured out thanks to someone smarter than me that instead of writing a bunch of plug-ins I could just do

Code:

        $this->r = new Renderer();
        $this->tpl->assign_by_ref('r', $this->r);


And when in the TPL files I could just do:

Code:

{$r->myFunction()}
{$r->myVar}
{$r->myArray.value}
{insert name="someInsertFunction" someVar=$r->text.someVar}
{$r->isSubscribed($foo.rss_feeds_id)}
{foreach from=$r->feeds(true, $users_id) item=foo}


Etc.

This allows me to create and control what I put in renderer objects, with the option of extending each other. If I needed a new function I could just add it to my Renderer object(s). I could use static variables in my functions to prevent them from being called twice redundantly, a ton of possibilities.

Furthermore, all "inline code" gets discouraged. If you need some "display logic" it goes in the Renderer() object. So a designer doesn't have to look at the code in the template. It's in an intermediary object.

Again, the fact that I can do this with Smarty in the first place is a big plus. Kudos to being awesome But right now I have to mix and match $r->functions() and "smarty_random_globalspace_functions()" which feels like 1999. Smarty is an Object, I fail to see why such a big chunk of it remains in global space.

Ok, thanks for reading. Good luck with the new version, keep it flexible!

EDIT:

Quote:

Since all plugins are now classes (did I mention that yet?), They all extend
Smarty_Internal_PluginBase, which makes $this->smarty a reference to the Smarty
object instance. This is available to all plugins.


Just noticed the above, perhaps everything I wrote is redundant. Excellent! I will check out the Beta when it's available.
Back to top
View user's profile Send private message
Fenn
Smarty Rookie


Joined: 28 May 2003
Posts: 11

PostPosted: Fri Oct 24, 2008 8:47 am    Post subject: Reply with quote

mohrt wrote:
Quote:
I just checked out the latest Smarty 3a SVN. Did you get rid of the idea of multiple Smarty instances? Was there a reason for that? I kinda liked the idea, however, I can think of one or two problems it might introduce.


I got rid of multiple instances because it caused problems with autoload (no way to pass id to reference which instance.) For now, it is a singleton instance. There should be no reason to run multiple instances of Smarty anyways. We'll see what crops up.


Actually I've found having multiple instances of Smarty handy on occasion. For example, the CMS I built for our company spits out the them markup stored in a database into a $doc_content template var for simple pages. But when The Powers That Be demanded that the CMS could also be used for surveys a different approach was needed. A survey needs more structure than HTML markup alone, it also needs to know what questions are being asked and how to validate the responses, etc.

The method of my survey class that generates the markup for the survey uses a Smarty template to build the markup from the list of questions the editor has specified. I then use fetch() to return it as a HTML string. So the first time somebody views a new survey the script requires 2 Smarty instances, one to turn the form into markup, and another to put the generated markup into the template presented to the user.

Singletons have a lot of problems, which ultimately boil down to the fact that a singleton is to all intents and purposes a fancy global var. It also changes the accepted behaviour of the class model, in that you expect to get a new instance of a class, not a reference to the only existing one.

http://www.oreillynet.com/cs/user/view/cs_msg/23417
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3 All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
Page 3 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