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

Assign to arrays
Goto page Previous  1, 2
 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
volkris
Smarty Rookie


Joined: 08 Jul 2003
Posts: 11

PostPosted: Sat Jul 12, 2003 7:10 pm    Post subject: Reply with quote

Oh, but I am talking about enterprise readiness.

I think I'm looking for a higher level of seperation than you are, which is often suited to an enterprise environment where the php team will have moved on while the template team is still working on a page. You admit that your solutions require a lot more back and forth between the teams, with the php having to know more about how the template works.

I want my php team to be able to say, "Ok, we've given you template guys all of the informaiton you need to display, now leave us alone," without the template team coming back later saying, "Yeah, thanks, but hey we need the object you passed to have method x, so stop working on the next page and come modify this one."

Again, this is especially important in my situation where not only will the php guy be moving on to a different project, but he often won't even be immediately available to go back and forth with the template guy.

So I suppose we just think differently on the importance and degree of seperation. And of course I think that's the entire purpose of templates in the first place Smile
Back to top
View user's profile Send private message Send e-mail
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Jul 12, 2003 8:47 pm    Post subject: Reply with quote

Volkris, take a look at what you are doing. My point is that you aren't separating your code and cetrtainly, you are not aiming for a higher form of abstraction than I have been pointing towards. If you were, you wouldn't be building data structures in your templates. It is *NOT* sufficient for your PHP guys to simply dump data in its rawest form to your template designers and tell them to run with it.

When I say you are not talking about enterprise readiness I am refering to the fact that you say that you can't rely on your PHP coders to be available. What kind of enterprise works like that?
Back to top
View user's profile Send private message
volkris
Smarty Rookie


Joined: 08 Jul 2003
Posts: 11

PostPosted: Sun Jul 13, 2003 1:01 am    Post subject: Reply with quote

I'm not at all dumping in the rawest form, I'm dumping data exactly as it needs to be displayed. I just feel like it's Smarty's job to do things like apply modifiers and generate list based html elements, and without arrays Smarty can't both apply modifiers and generate list based html elements.

MANY enterprises work like that. In all of the corporate web development I've done it's always been somewhat like that. Now I'm working with a smaller organization, not a business, and just because of who they've hired not everyone will be available at all times. This isn't a problem at all so long as the templates can go from data to display.

But as for enterprises: they normally meet at the beginning and decide what information the template desigeners will need, the database guys make sure it's available (which normally doesn't require much work), then the business logic guys take care of all of the processing needed to get the informaiton into and out of the database, they sort it, and everything else. Finally the web/template guys go all the way from sorted data to output (working with graphical designers, layout, etc).

But very often this last stage takes a whole lot of time and many iterations. Sometimes a customer will even decide midfight to change the display, but not the data displayed, significantly.

Meanwhile the business logic guys will have moved on to different projects needed by different web/template groups. Or they may have moved on to the next section of the site the the web guys will get to when they will. Or they might even have been contract workers whose contracts have expired after they finished their part.

This is serious. Requiring the php guys to be available for the web guys as they go through their iterations is very bad for many development patterns. It could require a company to keep contract workers on for weeks just idly waiting for a call from the web guys, wasting a lot of money. It could cause the business logic guys to have to drop their current projects to revisit old ones, breaking their workflow and hurting their productivity. It could even interfere with other web teams as they compete for attention from business logic guys, assuming the company hasn't wasted money on more business logic guys than they really need.

This problem doesn't exist between the db guys and the business logic guys; php is able to do all it needs to do so long as it gets the raw data. This allows php to be a true enterprise system. Under your ideas Smarty requires this type of interaction between its developers and the php guys, and this seriously subtracts from its enterprise-readyness.
Back to top
View user's profile Send private message Send e-mail
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Jul 13, 2003 10:39 pm    Post subject: Reply with quote

volkris wrote:
I'm not at all dumping in the rawest form, I'm dumping data exactly as it needs to be displayed.

That would imply that you don't have an issue or feature request. Be honest. The most interesting thing is this: You don't seem to realize that your real beef is with the operation of a supplied PLUGIN, not a language feature. The html_* plugins are not part of the Smarty core any more than the included modifiers are. Note that you can do EXACTLY what you want if you eschew the plugins (which you seem to like doing since you don't want to actually have to write any of your own) and use either custom {section} or {foreach} blocks. Or you can build a better plugin that actually does what you want. Or you can use the {append} plugin that messju suggested to get the functionality you requested from the start. It sounds more and more that it isn't that Smarty doesn't do what you need it to do but instead that you are (for whatever reasons) unwilling to customize Smarty in any way at all--and I don't mean with hacks or patches to the core--I'm talking about straight up customizations using the API. That's how everyone else does it, yet you want the core of Smarty changed for everyone.

Anyways, I'm not going to respond in point to all of your assertions as I don't think either of us are really expanding the state-of-the-art here. I find that when discussions start concerning themselves with the "enterprise" they become too nebulous to be of much use to anyone as hardly any point made is provable or has consequences that can be directly measured using standard metrics.

For example, every "enterprise" project I have been party to made a thorough investigation of tools prior to starting any work. Where the tools did not cover a needed design either a new tool was chosen or if possible, the existing tool was extended. There you have it. You chose Smarty. Smarty can do nearly everything you want even though you are using a pattern that is not well supported by Smarty. Yet Smarty's clever API is flexible enough to even allow your design pattern to be implemented in a simple way with only a small plugin.

So what more do you really want? Do you still think that Smarty is somehow lacking because it doesn't come with array building features right out of the box? I don't though but my hunch is that you do Smile

Thanks once again for an interesting discussion, Volkris. Now put a fork in me 'cause I'm done.
Back to top
View user's profile Send private message
volkris
Smarty Rookie


Joined: 08 Jul 2003
Posts: 11

PostPosted: Mon Jul 14, 2003 12:54 am    Post subject: Reply with quote

Ok, end of discussion (even though you're mischaracterizing my suggestion), but I'm going to take the last word Smile

What it comes down to is that Smarty simply doesn't have built in piping needed to do formatting on anything that will travel as a list to a different plug in.

There are a couple of ways around this (that preserve Smarty's sereration of business logic and display logic), including the reimplementation of list-based plugins without using lists (not a good solution because of usability and lack of code reuse) and the implementation of custom array-handling functions. The latter has drawbacks in that no matter how good the functions are written, arrays would never be as native to Smarty as normal variables.

And finally, needing to format data inside of list-based elements (tables, lists, form elements) is extremely common, and lack of ability to do this out of the box shows up as a gaping hole in any corporate environment.

PHP has managed to cross the line from project to accepted enterprise solution, but things like this are keeping Smarty out of that class.




PS, I have no problem writing extensions. I have a small library of them already written, another reason I don't want to jump to a different engine.
Back to top
View user's profile Send private message Send e-mail
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Jul 14, 2003 8:00 am    Post subject: Reply with quote

volkris wrote:
... but I'm going to take the last word Smile

wrong, obviously. Smile

volkris wrote:
... What it comes down to is that Smarty simply doesn't have built in piping needed to do formatting on anything that will travel as a list to a different plug in.


wrong, php comes with loads of functions operating on arrays and every php-function can be used as a variable-modifier in smarty.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
lsemel
Smarty Rookie


Joined: 18 Aug 2003
Posts: 5

PostPosted: Mon Aug 18, 2003 10:31 pm    Post subject: Assign to arrays Reply with quote

My website has a top nav consisting of a number of links. In my header.tpl, I would like to be able to do the following:

1) Assign the names and URLs of the section to parallel arrays.
2) Cycle through them and print them out.
3) If the user is in one section (as determined by a variable passed to the template) make it bold, otherwise make it a link.

This is something very simple to do in PHP, and apparently very complex to do in Smarty. How do you suggest I do this without assigning to an array and looping through it?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Nov 11, 2003 2:09 am    Post subject: Reply with quote

Soap-box aside, for those who really want to do things like this, I think the simplest thing is to leverage Smarty's php function-as-modifier capability.

eg:
Code:
{$array1|array_merge:$array2}
Back to top
View user's profile Send private message
giksos
Smarty n00b


Joined: 23 Mar 2006
Posts: 3

PostPosted: Thu Mar 23, 2006 6:05 am    Post subject: Need for array assignment Reply with quote

hello,

I recently tried to use smarty and the lack of array support was the first thing I stumbled upon. My point is that proper support of arrays cannot be achieved by adding plugins, because other plugins still would not support that.

Example: I recently had a template that first prepared table cells and then output them using html_table. The best way I could do it was:
Code:

   {php}
      $this->assign('cells', array());
   {/php}
   
   {foreach ...}
      {capture assign=cell}
                    (some cell content here)
      {/capture}
      {php}
         $this->append('cells', $this->get_template_vars('cell'));
      {/php}
   {/foreach}

   {html_table loop=$cells}


You see, the problem here is that capture cannot assign its output to an array element. There are other built-in and custom functions that have the same problem. Am I correct in saying that this cannot be fixed by just extending smarty?

Maybe there is any better way of doing what I want to do? Preparing all arrays in PHP doesn't seem to be a good idea, because the array in my code clearly arises only out of presentation needs.

Cheers,
Misha
Back to top
View user's profile Send private message
Design
Smarty Rookie


Joined: 17 May 2006
Posts: 8
Location: Maranello (MO), Italy

PostPosted: Wed May 17, 2006 2:43 pm    Post subject: Re: Assign to arrays Reply with quote

volkris wrote:
I'd like to be able to {assign} to arrays somehow, just like one can {assign} to normal variables.


I wrote a new plugin that can do exactly what you want: http://smarty.incutio.com/?page=set

To create a simple array:
{set var=$foo value=array('one', 'two', 'tree')}
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
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 -> Feature Requests All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
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