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
U.Tews
Administrator


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

PostPosted: Thu Oct 16, 2008 1:24 pm    Post subject: Reply with quote

Quote:
class Smarty Implements ArrayAccess { ...


Thanks for the input. But Smarty2 did already support that you pass an array with varibale assignments with a single call to the assign method.

The current status of Smarty3 Alpha is that you can opionally pass such array also directly to the display call. $smarty->display('my.tpl',$mydataarray);
Back to top
View user's profile Send private message
Notromda
Smarty Rookie


Joined: 30 Aug 2004
Posts: 13

PostPosted: Thu Oct 16, 2008 2:50 pm    Post subject: Reply with quote

U.Tews wrote:
Quote:
class Smarty Implements ArrayAccess { ...


Thanks for the input. But Smarty2 did already support that you pass an array with varibale assignments with a single call to the assign method.

The current status of Smarty3 Alpha is that you can opionally pass such array also directly to the display call. $smarty->display('my.tpl',$mydataarray);


You missed the point... By implementing that interface, it makes a nicer syntax for the assign statment. (I hate arrows)

Code:

$smarty['title'] = "Note the brackets on \$smarty";
$smarty['items'] = array("This", "is", "not", "the", "array", "I", "meant");

$smarty->assign("moreItems", array("You can do this already, I know; ",
                          "but the ArrayAccess provides some syntactic sugar ",
                          "that looks better.");
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Oct 16, 2008 2:57 pm    Post subject: Reply with quote

It won't happen, it just adds confusion. This is just as easy:

Code:
$smarty->assign('foo','bar');


Or you can do this:

Code:
$myvars['title'] = 'foo';
$myvars['name'] = 'bar';

$smarty->display('index.tpl',$myvars);


Or, what will be happening internally in Smarty 3 anyways:

Code:
$myvars = new Smarty_TplVars;
$tpl_vars->assign('foo','bar');
$smarty->display('index.tpl',$tpl_vars);
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: Thu Oct 16, 2008 3:02 pm    Post subject: Reply with quote

Not to mention, templates are objects now, so you will be able to so something like this:

Code:

$tpl = new Smarty_Template('index.tpl');
$tpl->assign('foo','bar');

$smarty->display($tpl);


For most, $smarty->display() encapsulates all that.
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


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

PostPosted: Thu Oct 16, 2008 3:10 pm    Post subject: Reply with quote

Notromda

Quote:
You missed the point... By implementing that interface, it makes a nicer syntax for the assign statment. (I hate arrows)

What I was saying was that you could use
Quote:
$myvars['foo'] = 'bla';
$myvars['bar']=3;

$smarty->assign($myvars)


already in Smarty2
Back to top
View user's profile Send private message
Spuerhund
Smarty Rookie


Joined: 20 Jan 2005
Posts: 16

PostPosted: Sat Oct 18, 2008 2:40 pm    Post subject: Reply with quote

What i really need and Smarty doesn't offer yet is a simple way to save the "Content-Type" header together with the output in the Smarty cache. For example: you have different templates to generate different outputs.
1) simple (X)HTML pages (needs application/xhtml+xml)
2) a template for the Atom feed (needs application/atom+xml)
3) a template that generates Javascript/CSS/something else (needs text/javascript, text/css or something else)

I don't want to run through the PHP logic which tells me of which content type the response should be. Maybe even database lookups are needed for this which makes it very expensive.

I calculated the Atom feed ONCE and it was saved in the cache for quick responding in the future. That means, there should be a way to save the content type in the cache as well and to read it from the cached file so that i don't have to run some more-or-less complicated PHP logic but just read it from the file and send it as Content-type header and that's it.


Another nice-to-have feature would be to offer a feature that whenever a file is added to the cache the gzip-compressed-version is added as well. When a file exists in the cache and the user agent accepts gzip encoding we could send him the gzip compressed file immediately without starting the compression again from scracht for every user.

Most browsers nowadays support content compression and by compressing the file only once and sending it to 1000 visitors we save a lot of CPU time that would otherwise be needed to compress the same file again for all 1000 people.


Did i already mention that i expect Smarty 3 to use mb_* functions wherever needed to be compatible with utf8 encoding? For example, what is the use of a truncate plugin that works only with ASCII text? Confused Rewriting all plugins myself so that they can do this just because my template engine has no idea about text encodings is really bad software design.
Back to top
View user's profile Send private message
cjxxi
Smarty Regular


Joined: 03 Aug 2007
Posts: 40
Location: Fort Worth,Texas

PostPosted: Sat Oct 18, 2008 3:05 pm    Post subject: Reply with quote

Celeb wrote:


I also like getting rid of {section} and introducing {for}. It just seems more .. PHPy Smile


If you do this , I would suggest not to "get rid of" it.. .. just mark it as deprecated.

I also like the idea Smile
_________________
CJAX THE PHP AJAX FRAMEWORK AT CJAX.NET
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
cjxxi
Smarty Regular


Joined: 03 Aug 2007
Posts: 40
Location: Fort Worth,Texas

PostPosted: Sat Oct 18, 2008 3:20 pm    Post subject: Reply with quote

1. is there a way for external developers to become smarty contributor?

2. to make changes to smarty do I need to be added to a certain group in the repository?
_________________
CJAX THE PHP AJAX FRAMEWORK AT CJAX.NET
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
mohrt
Administrator


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

PostPosted: Sat Oct 18, 2008 3:27 pm    Post subject: Reply with quote

cjxxi wrote:
1. is there a way for external developers to become smarty contributor?

2. to make changes to smarty do I need to be added to a certain group in the repository?


You can start by submitting patches here in the forums or on the dev mailing list for all to comment.
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: Sat Oct 18, 2008 3:29 pm    Post subject: Reply with quote

Spuerhund wrote:
What i really need and Smarty doesn't offer yet is a simple way to save the "Content-Type" header together with the output in the Smarty cache. For example: you have different templates to generate different outputs.
1) simple (X)HTML pages (needs application/xhtml+xml)
2) a template for the Atom feed (needs application/atom+xml)
3) a template that generates Javascript/CSS/something else (needs text/javascript, text/css or something else)

I don't want to run through the PHP logic which tells me of which content type the response should be. Maybe even database lookups are needed for this which makes it very expensive.

I calculated the Atom feed ONCE and it was saved in the cache for quick responding in the future. That means, there should be a way to save the content type in the cache as well and to read it from the cached file so that i don't have to run some more-or-less complicated PHP logic but just read it from the file and send it as Content-type header and that's it.


Another nice-to-have feature would be to offer a feature that whenever a file is added to the cache the gzip-compressed-version is added as well. When a file exists in the cache and the user agent accepts gzip encoding we could send him the gzip compressed file immediately without starting the compression again from scracht for every user.

Most browsers nowadays support content compression and by compressing the file only once and sending it to 1000 visitors we save a lot of CPU time that would otherwise be needed to compress the same file again for all 1000 people.


Did i already mention that i expect Smarty 3 to use mb_* functions wherever needed to be compatible with utf8 encoding? For example, what is the use of a truncate plugin that works only with ASCII text? Confused Rewriting all plugins myself so that they can do this just because my template engine has no idea about text encodings is really bad software design.


HTTP headers are normally handled in the application (PHP). If Smarty3 doesn't do exactly what you want, you could design your caching system however you wish with a custom cache resource. Maybe we could add a content type to the cache data, among other useful meta data.
Back to top
View user's profile Send private message Visit poster's website
cjxxi
Smarty Regular


Joined: 03 Aug 2007
Posts: 40
Location: Fort Worth,Texas

PostPosted: Sun Oct 19, 2008 9:29 am    Post subject: Reply with quote

mohrt wrote:
cjxxi wrote:
1. is there a way for external developers to become smarty contributor?

2. to make changes to smarty do I need to be added to a certain group in the repository?


You can start by submitting patches here in the forums or on the dev mailing list for all to comment.


I agree. However I would feel more comfortable to get started if I was givent/assigned something todo and then I can create a patch and post it
_________________
CJAX THE PHP AJAX FRAMEWORK AT CJAX.NET
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Shadzik
Smarty Rookie


Joined: 01 Aug 2007
Posts: 5

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

Do you think about php5.3, unicode and Namespace ? It could resolve some problems. Like extracting array to single variables in PHP-style Templates.
Cache should be made as plugin or something like this to decide where do you want to save your cache. not only files but database or memcache.

Maybe plugins should be made as Small objects and will be loaded by autoload. Not always all plugins are needed. Every type of plugins (block, modyfier, output) could have there own plugin interface.

For debugging could have some API to get all debug data and make with them all you want, Put it into a formated xml or txt, give them to javascript or like in Smarty 2 use special template.

ShortTags are "Pure Evil"
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 1:30 pm    Post subject: Reply with quote

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.


Quote:
Cache should be made as plugin or something like this to decide where do you want to save your cache. not only files but database or memcache.


Already in the works.

Quote:
Maybe plugins should be made as Small objects and will be loaded by autoload. Not always all plugins are needed. Every type of plugins (block, modyfier, output) could have there own plugin interface.


Already done, and plugins are lazy-loaded. (PHP's autoload feature is avoided.)

Quote:
For debugging could have some API to get all debug data and make with them all you want, Put it into a formated xml or txt, give them to javascript or like in Smarty 2 use special template.


Debugging is not implemented yet in alpha, all good ideas.
Back to top
View user's profile Send private message Visit poster's website
kiboke
Smarty n00b


Joined: 20 Oct 2008
Posts: 2

PostPosted: Mon Oct 20, 2008 1:43 pm    Post subject: for loops Reply with quote

Hello,

why don't you replace loops like this one

Code:
for ($x = 0, $y = strlen($string); $x < $y; $x++ ) { ... }


with

Code:
for ($x = 0; isset($string[$x]); ++$x) { ... }


There is ona variable less in the code and memory, une function less, and ++$x is a little bit faster than $x++.

And what about abandoning for loops alltogether and use (even faster) do-while loop?

I think those changes are important if we want smarty to be very fast.[/code]
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 1:51 pm    Post subject: Reply with quote

You will have {for ...} directly available in the template.
Back to top
View user's profile Send private message Visit poster's website
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 2 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