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
mohrt
Administrator


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

PostPosted: Fri Oct 24, 2008 3:29 pm    Post subject: Reply with quote

If you notice in alpha, you can create multiple instances of template objects:

Code:
$myTpl = $smarty->createTemplate('foo.tpl');
$myTpl->assign('foo','bar');
echo $myTpl->getRenderedTemplate();


The Smarty singleton itself is just a subclass of a template object, and encapsulates all this internal going on with familiar smarty syntax.

Therefore, even though there is one singleton, you can spawn multiple tpl objects from that singleton.
Back to top
View user's profile Send private message Visit poster's website
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Tue Oct 28, 2008 2:44 pm    Post subject: Reply with quote

First off: way to go. What I've seen thus far looks

Why was PHP's autoload abandoned? What's bothering you about the way SPL autoload works? Not that I miss it, but i don't get the point of getting ridd of it, since it perfectly suits my needs.

There's already been questions about caching gzipped output and saving the Content-Type header along the cached output. What i'm missing here is a rather flexible approach to the If-Modified-Since issues. In Smarty2 caching headers were practically ignored if {includes} or non-caching functions/blocks were used inside the template. I would *really much* like a way to specify if the contents of those "dynamic" parts really require the loading of the page, or could just return a freaking timestamp telling the last-modified time. That way you actually *could* build cache-friendly applications, without losing the benefits of Smarty's great flexibility. If dynamic contents could tell their (real) modification times, deploying cache-friendly pages would not be rocket-science and thus far more applied than they are today. I'd appreciate it, if constructs obstructing the very simple handling of If-Modified-Since/Not Modified could be queried if they actually changed since the given timestamp. All constructs now seem to be separate classes, therefore it should seem fairly easy to have them implement a contentChangedSince()-method. Programmers intending to make use of the-more-useful-HTTP-stuff could have their proprietary constructs react to If-Modified-Since headers. Getting what i'm talking about?

It would also be nice if a non-caching function nested inside a non-caching block would not result in the function being called without arguments, when reading from cache. (A bug in Smarty2 that drove me crazy like nothing else)

Some people use Smarty to generate all sorts of output. X/HTML, Javascript, JSON, XML, younameit. I pretty much hate building XML-docs without my DOM. I don't get the use of Smarty for merely calling json_encode from within the template. I feel the urge to run away when seeing PDFs generated the same way. Yet i still do all that absurd crap - just to have one single interface for controlling the output my application generates. I would love to see some functionality to handle the same data being distributed in various formats (html,json,rss,atom,xml,pdf,..). Primarily functionality that acts like another cache-group on top of the same template-resource (so flushing one template's cache-group gets ridd of all formats derived from that data-set). Seeing "self-compiled" (php-only) templates in Smarty3 should blast my initial points into oblivion, since no text-based template has to be launched to utilze smarty's output cache.


In short:
* Enhance dynamic functions/blocks with the functionality to determine if a »304 Not Modified« can be sent, although the function/block might be declared dynamic.
* Provide abstraction for different formats for the same data-set, with the goal of simplifying the caching of the same data in different formats. (practically introducing "template-groups")
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: Tue Oct 28, 2008 3:01 pm    Post subject: Reply with quote

Quote:
Why was PHP's autoload abandoned?


Autoloaded methods do not get the benefits of a PHP op-code cache, and that is crucial to your application's performance. It's pretty easy to get around anyways.

Quote:
In short:
* Enhance dynamic functions/blocks with the functionality to determine if a »304 Not Modified« can be sent, although the function/block might be declared dynamic.
* Provide abstraction for different formats for the same data-set, with the goal of simplifying the caching of the same data in different formats. (practically introducing "template-groups")


Since all templates, cache files, functions, etc. are objects, it will be pretty easy to pass meta-data around with them. Your points should be straight forward to address. Some of them are that I know of (such as dynamic variables to non-cached funcs.) Take a closer look when we get to beta, we'll see what we have covered. If it's not there, it's easy to extend and get what you want.
Back to top
View user's profile Send private message Visit poster's website
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Tue Oct 28, 2008 3:39 pm    Post subject: Reply with quote

mohrt wrote:
Autoloaded methods do not get the benefits of a PHP op-code cache, and that is crucial to your application's performance. It's pretty easy to get around anyways.


Never heard that one before. Maybe i should reconsider my use of autoload... thanks for the hint, though.

mohrt wrote:
Since all templates, cache files, functions, etc. are objects, it will be pretty easy to pass meta-data around with them. Your points should be straight forward to address. Some of them are that I know of (such as dynamic variables to non-cached funcs.)


Oh, even cache-files are supposed to be objects? Smarty3 seems to be getting more interesting by the minute Wink

mohrt wrote:
Take a closer look when we get to beta, we'll see what we have covered. If it's not there, it's easy to extend and get what you want.


I'll keep peeking in - thanks for the reassurance, looking forward to the beta.
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: Tue Oct 28, 2008 4:18 pm    Post subject: Reply with quote

Quote:
Oh, even cache-files are supposed to be objects?


Cache files, regardless of their resource type (files, db entries etc.) will contain meta-data, so you can think of them as a serialized object.
Back to top
View user's profile Send private message Visit poster's website
DarkBorg
Smarty n00b


Joined: 30 Oct 2008
Posts: 1

PostPosted: Thu Oct 30, 2008 3:14 pm    Post subject: Reply with quote

Will smarty be completely camelCase? Would be cool, this is one thing about Smarty 2.0 that bothers me a bit...

I took a look at the Sourcecode, looks sexy Smile
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Wed Nov 12, 2008 2:07 pm    Post subject: Reply with quote

I'm pretty excited about 3.0. Is there a comprehensive list of all of the anticipated features anywhere?

Also, if I can contribute to coding or anything else, let me know how.


thanks.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Dec 16, 2008 11:57 pm    Post subject: Reply with quote

douglassdavis wrote:
I'm pretty excited about 3.0. Is there a comprehensive list of all of the anticipated features anywhere?

Also, if I can contribute to coding or anything else, let me know how.


thanks.


There is a README with the alpha, although it isn't a complete feature list. You can contribute by testing the alpha version and posting your findings to the developer list (or here.)
Back to top
View user's profile Send private message Visit poster's website
mniskanen
Smarty Rookie


Joined: 26 Apr 2003
Posts: 20
Location: Lieksa,Finland

PostPosted: Thu Jan 15, 2009 12:23 pm    Post subject: Reply with quote

mohrt wrote:
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.


I have written a fully blown web application framework that makes use of Smarty 2.x. It includes a smarty plugin called "cmsmodule" which creates the respectived cms module class instance, makes it load the parameters and finally calls its fetch() method. My applications make use of several plugins, say:
Code:

<body>
...
{cmsmodule name="menu_vertical" src="db" dbtable="mainmenu"}
...
{cmsmodule name="news" dbtable="mynews"}
</body>



Now each of thes modules work a bit like this
Code:

class news_module extends cms_module {
include libs/Smarty.class.php" ;
  function fetch(){
    $_smarty = new Smarty();
    ... fill the template...
    return $_smarty->fetch("news.tpl"); // a small, simple template
  }
}


Most modules create a Smarty instance for thein own private purposes and not interfere with the "mother" Smarty instance (at least with Smarty 2.x). Will the "singleton" approach break my framework completery? That is: do I have to take into account the singleton when naming template variables, for instance, so that filling stuff for one module will not trash my main.tpl?

Markku
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Jan 15, 2009 3:16 pm    Post subject: Reply with quote

Markku

This will not be a problem at all. Smarty3 alows to assign variables to individual templates. Your class could look like this:

Code:

class news_module extends cms_module extends Smarty_Internal_Base {
  function fetch(){
     $_tpl = $this->smarty->createTemplate("news.tpl");  // create template object
    ... fill the template...
    $_tpl->assign('foo','bar');  // assign variables private for this template
    .....
    return $this->smarty->fetch($_tpl); // a small, simple template
  }
}
Back to top
View user's profile Send private message
mniskanen
Smarty Rookie


Joined: 26 Apr 2003
Posts: 20
Location: Lieksa,Finland

PostPosted: Thu Jan 15, 2009 4:05 pm    Post subject: Reply with quote

U.Tews wrote:
Markku

This will not be a problem at all. Smarty3 alows to assign variables to individual templates.


Whew, thank you. That looks very nice indeed and I feel very, very relieved now. I think I will have a good look at the current SVN stuff as soon as I have the time.

My modules being relatively small due to my minimalist approach I do not think it should take much time to convert them to the new style. And the main Smarty class looks very small indeed now. Having used Smarty for more than six years now I am happy to see the new development in progress. I will keep monitoring the status from now on!

Markku
Back to top
View user's profile Send private message
c960657
Smarty Regular


Joined: 07 May 2003
Posts: 75
Location: Copenhagen, Denmark

PostPosted: Mon Feb 16, 2009 10:06 pm    Post subject: Reply with quote

Perhaps I am joining the discussion a bit late, but hopefully not too late Smile I have not studied Smarty3 closely yet, so my comments are mostly based on experiences with Smarty2.

  1. It would be convenient if custom modifiers had access to the Smarty and Template instances like template functions have.

  2. When I make custom template functions, I often add support for an assign parameter like the one for {cycle}, i.e. {cycle values="a,b" assign=myvar}. I suggest adding an assign modifier modifier that can be used with all template functions for assigning the output to a variable, i.e. {cycle|assign:"myvar" assign=myvar}.

  3. If you have a big HTML file, it is useful to split it up and put the individual parts in seperate files that are included using {include}. To do this in Smarty2, the parent template file must have its own path hardcoded, e.g. {include file="very/long/subdir/structure/part1.tpl"}, or it can look it up using {assign var=dir value=$smarty.template|dirname}{include file="$dirname/part1.tpl"}. It would be nice with an easier way to do inclusions using relative paths.

  4. I have a large number of loosely coupled projects that each offer some Smarty plugins. In order to allow Smarty to discover these plugins, I must either set $smarty->plugins_dir to a big array of all projects, or I can set it to one dir that contains symlinks to all other projects. Neither is easy/cheap to do at runtime, so I currently use a command-line script to setup these paths whenever I add a project. It would be convenient with some kind of callback mechanism (a la autoload for classes) that is invoked when Smarty needs the path to a particular template and/or a callback when the compiler is invoked. This would also allow the automatic creation of compile_dir's at runtime and other expensive operations that are only done in the relatively rare occasion that a template is compiled.

  5. In Smarty2, custom resource types are 2nd class citizens compared to the file resource type that is treated specially many places in Smarty.class.php. I hope Smarty3 will have a cleaner cut so that custom resource types become as powerful as file resource types (it looks like this is already the case).

  6. As I understand resource types, they can be considered "virtual filesystems", i.e. places where templates are stored. This understanding seems incompatible with the new php resource type - php resources are files in the filesystem just like file resources, just with a different syntax/semantics. I suggest an alternative approach: Resource types are just places to store files. Whether the file is interpreted as Smarty template code ({html_table loop=$foo}), pure PHP (<?php bar(); ?>) or perhaps some future XML-Smarty-variant (like the syntax used in ASP.NET, <smarty:html_table loop="$foo" />) is determined by something similar to a MIME type reported by the resource implementation. This pseudo-MIME-type (or "syntax type") maps to individual compilers (in the basic setup this is the existing Smarty_Internal_Compiler and an almost empty class that basically just passes PHP files through). The file based resource can return the type based on the file extension (.tpl, .php and .xtpl for the three examples) - or perhaps it can be contained in the template itself (like the XML prolog, <?xml version="1.0" charset="ISO-8859-1"?>). The string based resource type can use a syntax similar to the one used by the data: URI scheme, e.g. "string:type=tpl,{$foo}" or "string:type=php,<?php echo time() ?>".

  7. A general method for returning metadata about each resource (as described above) would also make it possible to specify settings per file that can currently only be specified globally, e.g. $left_delimiter, $right_delimiter, $compile_check etc. These can either be specified by the resource implementation (similar to HTTP headers), or specified inline (like the XML prolog).

  8. I'll be happy to discuss or elaborate these suggestions, or to tell about how we use Smarty in the company I work for. I'll probably have more comments when I get a chance to think more about this Smile

To what extent is Smarty3 supposed to be backwards compatible with Smarty2?
Back to top
View user's profile Send private message Visit poster's website
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Tue Feb 24, 2009 5:20 pm    Post subject: array syntax Reply with quote

Sometimes the array syntax confuses me.

For example, if I have a three dimensional array and want to iterate through a portion of it:

These two don't work:

<{foreach from=$myArray[$id][log] item=log_row }>
<{foreach from=$myArray[$id]['log'] item=log_row }>


But this does:
<{foreach from=$myArray[$id].log item=log_row }>

In Smarty 3, will

$someArray['indexname']

be allowed?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Feb 26, 2009 11:37 am    Post subject: Reply with quote

Yes Smarty3 does support $someArray['indexname'] ['index2']
Back to top
View user's profile Send private message
yankee
Smarty Rookie


Joined: 02 Mar 2009
Posts: 31

PostPosted: Mon Mar 02, 2009 7:52 pm    Post subject: Reply with quote

First of all: Thanks for smarty.

The thing that I hated most in smarty 2 was the inability to use math in templates. Something like {$myVar*2} was not possible and it forced me to use {php}-Sections just perform the most basic math operations.
I see that this has been dealt with in Smarty v3 and I like to express my appreciation Smile.

I think you should dedicate a forum for smarty3-dev so we can dedicate one thread to each issue making it easier to organize everything.

Anyway I started playing around with Smarty. First I created a php-File that displays a non-existing template. Executing the file from command line led to this error:
Code:
PHP Notice:  Undefined index:  QUERY_STRING in /home/yankee/proggen/php/smarty3/Smarty3Alpha/libs/Smarty.class.php on line 178
Code: 0

Obviously you did not anticipate that someone might my using smarty from command line and thus you ecpect the QUERY_STRING var to exist. you shouldn't. Easiest fix I can think of is:
Code:
Index: libs/Smarty.class.php
===================================================================
--- libs/Smarty.class.php       (revision 3012)
+++ libs/Smarty.class.php       (working copy)
@@ -174,7 +174,7 @@
         $this->loadPlugin($this->template_class);
         $this->loadPlugin('Smarty_Internal_Plugin_Handler');
         $this->plugin_handler = new Smarty_Internal_Plugin_Handler;
-        if (!$this->debugging && $this->debugging_ctrl == 'URL') {
+        if (!$this->debugging && $this->debugging_ctrl == 'URL' && ($this->request_use_auto_globals ? isset($_SERVER['QUERY_STRING']) : isset($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']))) {
             $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'];
             if (@strstr($_query_string, $this->smarty_debug_id)) {
                 if (@strstr($_query_string, $this->smarty_debug_id . '=on')) {

Next I hope that you will remember to remove this feature or to disable it by default to prevent this feature from being triggered in a production environment.
BTW: Why are you using $this->request_use_auto_globals? It should always be possible to use $_SERVER... no matter if auto globals are used or not.

I guess I'll be playing around a little with smarty. I think that I understood most of the basic design of smarty by reading the source code, but it would be helpful du have a little documtation that describes how which classes/function interact with each other and so on...
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 4 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