DooPHP IRC channel


DooView new features

Discussion about new desired features.

DooView new features

Postby ximian » Sat Dec 26, 2009 5:45 pm

Hi all.

Currently, i'm using Smarty 3 in all my projects.
I'm trying to evaluate dooview and what it's missing so that i can use it instead of smarty and, so far, i found 6 features i miss so that i can start thinking about smarty-dooview porting. These features are really useful and i think dooview and all designers that will work with it can really benefit.

  • function arguments as associative array
    This can be really usefull. Not all parameters are needed and designer should only defined what he want. Instead of just
    Code: Select all
    {{funct(par1,par2)}}

    dooview could accept associative array
    Code: Select all
    {{funct(str=something total=3 att=true)}}

    where template function will only accept one argument.. an array
    Code: Select all
    function funct( $params ){
      $params['str'] // 'something'
      $params['total'] // 3
      $params['att'] // true
    }

  • modifiers
    Yes, doophp supports modifiers (these can be interpreted as standard functions) but.. if you have 4.. 5.. in same call the syntax will become a mess:
    Code: Select all
    {{upper(bigger(truncate(margeit(addit(something)),3,60)),5)}}

    What do you think to include a better/cleaner syntax:
    Code: Select all
    {{something|addit|margeit|truncate:3,60|bigger|upper:5}}

  • calling class methods?
    Currently it's possible to access object variables
    Code: Select all
    {{winner.@Physical}}

    Executing object methods is really needed
    Code: Select all
    {{winner->getPhysical}}
    {{winner->getPhysical(1,2,3)}}
    {{winner->getPhysicals(color=red attribute=true)}} //asssociative

  • dooview method to compile custom tags.
    Imagine i have a tag 'mytag' that is always '12345' and i don't want to be dynamic, i mean i want to be really 12345 in php template file. Currently, i can assign 12345 to a data variable and display it.. but i don't want that. i want to compile it and make it static:
    Code: Select all
    $myview->addCustomCompile( 'mytag', '12345' );

    basically, this will become a entry inside DooView::compileTags()

    Code: Select all
    function DooView::compileTags(){
      ...
      $str = str_replace('mytag', '12345', $str);
      ...
      return $str;
    }

  • on loops, how to check if iteration is first or last?
    Code: Select all
    <!-- loop users -->
        {{users' v}}
        <!-- if users' first --> ...
        <!-- elseif users' last --> ...
        <!-- endif -->
    <!-- endloop -->

  • secondary view path. this is that most important feature i needed
    By default, dooview will search for original html files inside a primary folder (eg, protected/view/). currently i have a engine that will search inside the primary folder but, if template file not found, will search inside a secondary folder.
    Imagine you have 100 template folders, all template folder must have same structure! that's what i want to avoid!
    if the current template folder (eg, 86th theme folder) don't have the needed template file, the template engine will search for it in the core template view folder (where it exists for sure). This means that a template designer only need to create a html file if he don't want the output of the core template file.
    A way to define a secondary folder for dooview is really needed for me.

regards
Francisco A
ximian
 
Posts: 143
Joined: Wed Nov 25, 2009 1:51 am
Location: Portugal

Re: DooView new features

Postby leng » Sat Dec 26, 2009 6:18 pm

If this is going to be built I think it's going down the road smarty took and probably another complicated template language to replace PHP itself.
I don't think keys are better for designers as most are more common to pass in parameters rather than object/array based parameter (like python?)
{{funct(str=something total=3 att=true)}}

btw, the purpose of template tag was to let programmers mock up some helper tags for designers, so instead of
{{upper(bigger(truncate(margeit(addit(something)),3,60)),5)}}

I guess you would probably wrote a proper function that do the appropriate job?

Or probably have a function to called whatever function names passed in, I guess I will probably add this to the default templatetag.
Code: Select all
#can call from template {{callFunc(username, "upper|trim|substr:0,1")}}
public function callFunc( $str, $functions ){
    $functions = explode('|', $functions);
     foreach($functions as $f){
          call_user_func_array($f, ...)
     }
}


On loop, I assume you have an array of users (0,1,2,3,4,5...) , you can use key and count() ?
Code: Select all
<!-- loop users -->
    {{users' v}}
    <!-- if {{users' k}}==0 --> ...
    <!-- elseif  {{users' k}}=={{count(users)}}-1 -->
    <!-- endif -->
<!-- endloop -->


compile custom tag? Then, why not just write it in the template since it's always 12345?

Nope, no way to access objects methods as the template was to restrict designers, imagine I have a Model user with public method delete(). You have to make template tag for designer to access certain methods in that case. Or it is just you (programmer), you can always enable and mix in PHP tags with the view files.

secondary view path, do you mean sub folder? Yes you can do that with include 'path/path2/xxxx'
Just Doo IT!
leng
 
Posts: 1482
Joined: Thu Jul 16, 2009 11:33 pm

Re: DooView new features

Postby ximian » Sat Dec 26, 2009 6:58 pm

Why programmers only see by their point of view? :?
DooView should be a tool to make designer's life easier.

leng wrote:If this is going to be built I think it's going down the road smarty took and probably another complicated template language to replace PHP itself.
I don't think keys are better for designers as most are more common to pass in parameters rather than object/array based parameter (like python?)
{{funct(str=something total=3 att=true)}}

Not agree. When you have a function that can be used with multiple combinations there is only 3 perspectives of doing it.
1- one function with multiple combinations
2- multiple functions with one combination each
3- a mess: one function with static arguments

Imagine you can have funct/str=something,att=false, func/total=1,att=true, func/att=false
by perspective 1:
funct(str=something att=false)
funct(total=1 att=true)
funct(att=false)

by perspective 2:
functa(something,false)
functb(1,true)
functc(false)

by perspective 3:
funct(something,null,false)
funct(null,1,true)
funct(null,null,false)

Where is KISS here? Now, image if function has 5..6..arguments. Vote for 1st

leng wrote:btw, the purpose of template tag was to let programmers mock up some helper tags for designers, so instead of
{{upper(bigger(truncate(margeit(addit(something)),3,60)),5)}}

I guess you would probably wrote a proper function that do the appropriate job?

Yes, programmer can create a unique function that does all... and designer tools? Look by the designer point of view! I know that designer can use only one function instead of 200 functions.. but that is not what i'm talking about. I'm talking about how they are used:
1- {{upper(bigger(truncate(margeit(addit(something)),3,60)),5)}}
2- {{something|addit|margeit|truncate:3,60|bigger|upper:5}}

Imagine you are a designer (not a programmer!!).. and vote for KISS here. ;)

leng wrote:Or probably have a function to called whatever function names passed in, I guess I will probably add this to the default templatetag.
Code: Select all
#can call from template {{callFunc(username, "upper|trim|substr:0,1")}}
public function callFunc( $str, $functions ){
    $functions = explode('|', $functions);
     foreach($functions as $f){
          call_user_func_array($f, ...)
     }
}


Maybe doophp could interpreted both ways?

leng wrote:On loop, I assume you have an array of users (0,1,2,3,4,5...) , you can use key and count() ?
Code: Select all
<!-- loop users -->
    {{users' v}}
    <!-- if {{users' k}}==0 --> ...
    <!-- elseif  {{users' k}}=={{count(users)}}-1 -->
    <!-- endif -->
<!-- endloop -->


Well.. it is possible but.. a designer should not be a programmer, right?
Where is KISS here?

leng wrote:compile custom tag? Then, why not just write it in the template since it's always 12345?

They are called prefilters in smarty. Sometimes is useful to replace template code and compile it. This will make a template much much faster! Useful to remove unwanted comments, keeping an eye on what people are putting in their templates, etc..

leng wrote:Nope, no way to access objects methods as the template was to restrict designers, imagine I have a Model user with public method delete(). You have to make template tag for designer to access certain methods in that case. Or it is just you (programmer), you can always enable and mix in PHP tags with the view files.

Well, security reasons.. i see. On some big objects we must output everything even if designer don't use all properties.
The real problem is when we want to give designer a method and that method has a different output that is based on arguments.. not possible.
Maybe programmer should know that when assigning objects, all methods are visible to designers. This way he will assign only small objects with specific methods for designers.

leng wrote:secondary view path, do you mean sub folder? Yes you can do that with include 'path/path2/xxxx'

No, it's not a subfolder.

when you render paths/path2/xxxx, dooview will search for protected/view/paths/path2/xxxx or similar. why? because we have defined a primary path as protected/view/.
What if protected/view/paths/path2/xxxx is not found? .. error.

This feature is about a secondary path so that, we can define protected/view/ as primary and otherpath/view/ as secondary. This way, when we try to render paths/path2/xxxx, doophp will search for protected/view/paths/path2/xxxx but if not found will search in side secondary path, so will use otherpath/view/paths/path2/xxxx file.

Francisco A
ximian
 
Posts: 143
Joined: Wed Nov 25, 2009 1:51 am
Location: Portugal

Re: DooView new features

Postby RichardM » Sat Dec 26, 2009 7:32 pm

Hi Francisco,

I must say I would agree that support for all of the above would be nice. I am questioning right now working on a DooAdvancedView so that it would be possible to 'change' how things are done right now. One example in addition to the above is adding support for nested loops on different variables rather than a sub array of a parent array you are already iterating over. This is something which breaks backwards compatibility, and I foresee some of the things you have listed above would cause this to. If people would be interested in seeing some of the above in a new DooView class too please comment here...along with other things you might like to see and if there is enough interests I will look into it.

I have already taken a look at some engines and I really do not like the types of compiled files they generate...


Richard
Note: code samples my not be 100% accurate.
RichardM
 
Posts: 1329
Joined: Sun Aug 30, 2009 6:03 pm
Location: Cumbria, UK

Re: DooView new features

Postby leng » Sat Dec 26, 2009 7:42 pm

Ximian, you are forgetting the whole point of template engine!
All the features you are stating are "complicated" for a designer! Why should I a designer handle all these upper/lower/big/small, and heck, why should I even care on passing key=>value? I would just want you to give me an array of data and I simply loop through my list design, all I care about is CSS/HTML/Photoshop/JS.

Code: Select all
<!-- loop users -->
   <li>My list design</li>
<!-- endloop -->


If I were to handle all these, I would happily take up some simple PHP skills instead of learning another "PHP template engine language" which brings me to no where. It doesn't really make designer happy with functions, syntax and stuffs like that. It's really a waste of time to build another complex template engine to support "all stuffs that work in PHP".
Just Doo IT!
leng
 
Posts: 1482
Joined: Thu Jul 16, 2009 11:33 pm

Re: DooView new features

Postby RichardM » Sat Dec 26, 2009 7:56 pm

I'm torn between the two points of view. I want to see a more powerful template engine so I can do some more complex things with my views...but at the same time see the need to keep the template notation simple. Some of my views are starting to get 'over complicated' albeit having spent time refactoring my markup and way I have my template set out in general I have actually been surprised at how much 'junk' I had in my view in terms of logic from template functions.

I think there are some things which are needed and there is a need to avoid rewriting PHP in a view. I think also one needs to remember we can (I think) still place php tags directly within our view file and these will still work fine after the template engine has had its go at your code. As such it should still be possible for example to use Layouts with php tags in the view files and the view file would almost remain untouched when it comes out into the viewc folder. The only difference being that its content will have ended up inside the specified layout.


Richard
Note: code samples my not be 100% accurate.
RichardM
 
Posts: 1329
Joined: Sun Aug 30, 2009 6:03 pm
Location: Cumbria, UK

Re: DooView new features

Postby ximian » Sun Dec 27, 2009 12:55 am

leng wrote:If I were to handle all these, I would happily take up some simple PHP skills instead of learning another "PHP template engine language" which brings me to no where.

Why learning doophp? Everything can be done writing a bounch of php classes.
That's not the point. What is a template engine? My opinion is that it is a tool for a designer.. not for a developer.
And btw, a designer do not need to know what PHP is. My opinion.
Smarty is really the best template engine i found so far. It's powerful, it's used by millions of templates with a very intuitive syntax.. and in version 3 it's fast and error strict.
If DooView is what it's now, i really cannot use it. Why? Because is too simple and do not have the intuitive (read:KISS) syntax for powerful requirements.

RichardM wrote:want to see a more powerful template engine so I can do some more complex things with my views...

Well.. i really NEED. Otherwise i cannot use DooView at all.
RichardM wrote:but at the same time see the need to keep the template notation simple.

Me too, but with current implementation and examples like these.. that will become very dificult..
Code: Select all
<!-- loop users -->
    {{users' v}}
    <!-- if {{users' k}}==0 --> ...
    <!-- elseif  {{users' k}}=={{count(users)}}-1 -->
    <!-- endif -->
<!-- endloop -->

{{upper(bigger(truncate(margeit(addit(something)),3,60)),5)}}
...unless you use, like leng, simple template files that only have loops inside.

Francisco A
ximian
 
Posts: 143
Joined: Wed Nov 25, 2009 1:51 am
Location: Portugal

Re: DooView new features

Postby RichardM » Sun Dec 27, 2009 1:22 am

ximian wrote:Smarty is really the best template engine i found so far. It's powerful, it's used by millions of templates with a very intuitive syntax.. and in version 3 it's fast and error strict.
If DooView is what it's now, i really cannot use it. Why? Because is too simple and do not have the intuitive (read:KISS) syntax for powerful requirements.


I am not aiming to disagree with what you are saying. I to am finding loops / logic to start looking confusing in a couple of my own templates but if you really like smarty...It should be easy to configure your own base controller (which extends DooController) to use Smarty for your templates. This would then be used instead of the DooView class which would simply not be loaded by DooPHP and therefore in that way avoid it slowing your app down.

The other day I got Twig working fine and think smarty shouldn't take long. I also looked at a few other template languages but was not happy with them. Heard some things on phptal and the syntax looks quite nice but when looking over the docs i was not so sure. I think if I look at smarty one thing I will look at is how to get modules in DooPHP working with smarty.
Note: code samples my not be 100% accurate.
RichardM
 
Posts: 1329
Joined: Sun Aug 30, 2009 6:03 pm
Location: Cumbria, UK

Re: DooView new features

Postby leng » Sun Dec 27, 2009 4:09 am

Smarty is really the best template engine i found so far. It's powerful, it's used by millions of templates with a very intuitive syntax.. and in version 3 it's fast and error strict.
If DooView is what it's now, i really cannot use it. Why? Because is too simple and do not have the intuitive (read:KISS) syntax for powerful requirements.


The last time I check, "PHP" is the best template engine available in PHP.
What that make things complex is not PHP language (or DooView) but the application logic and operations where web designers will never give a #@$%@
Code: Select all
//these never look KISS or easier to designers
//hey, i will never do such thing in my views as programmer!
{{upper(bigger(truncate(margeit(addit(something)),3,60)),5)}}
{{funct(str=something total=3 att=true)}}
{{something|addit|margeit|truncate:3,60|bigger|upper:5}}


The only tool to make designer's life easier is Adobe (Dreamweaver/Photoshop/You name it!). The fact is I have to maintain things where designers don't understand. Most would probably even like to use native PHP with their expertise/experience with Wordpress themes.

But hey, if you really like a template engine that tries to do what's available in PHP, I think Smarty is the best choice.
http://www.sitepoint.com/forums/showthread.php?p=498687
Just Doo IT!
leng
 
Posts: 1482
Joined: Thu Jul 16, 2009 11:33 pm

Re: DooView new features

Postby ximian » Sun Jan 03, 2010 11:16 pm

leng wrote:http://www.sitepoint.com/forums/showthread.php?p=498687

Posts from Jul 2002 ? No thanks.

Leng this discussion is not about Smarty vs PHP. It's about DooView vs Smarty history/problems/features and how to learn with and not reinventing the weel.

Francisco A
ximian
 
Posts: 143
Joined: Wed Nov 25, 2009 1:51 am
Location: Portugal

Next

Return to Features Request

Who is online

Users browsing this forum: No registered users and 1 guest

cron