Re: [htmltmpl] Numeric loops
Brought to you by:
samtregar
From: Mathew R. <mat...@ne...> - 2007-04-30 02:41:10
|
>> If you just want to print 4 stars, then just do that. * * * * >> >> If you are looking for some indentation background, you could try >> something like the following on a div: >> >> style="background:url('star.gif') right repeat-y;" >> >> If you are looking for something like <TMPL_FOR 1..4> then you >> probably need to re-evaluate why you need it - maybe you need to re- >> think your original problem. That said, there have been previous >> discussions on whether the TMPL_xxx syntax should support user-defined >> extensions, and various people have their own hacks to allow such a >> feature (which would then allow you to build your TMPL_FOR). >> > > Well my problem is that sometimes I want to iterate through a numeric > range. If an article is ranked 4 stars then the designer can either > iterate through each ranking and display a star or he/she can simply > output "4 stars." (one customer likes the latter, another wants the > former). This is a pretty good example where we could consider H::T to be lacking. This type of UI choice is definitely something that is unrelated to business logic, and very much related to UI design - so one could argue that choice it should be implemented in the templates. In this case, I would argue for a case where H::T could be extended so that a TMPL_FOR could be used. [ In fact, had I have came across this same problem, since I use my modified version of H::T, I could have implemented a TMPL_FOR or something similar. ] > Likewise, I use Data::Page::Navigation for paginated data - > it's a really nice module, and if it displays 10 indexes at the bottom > of the page, say from 5 - 14, it would be nice if I could iterate > through them rather than doing it in Perl. It's not a religious > decision, it just gives the flexibility to the designers. > I haven't used Data::Page et al. but have previously created my own code to do similar. AFAICT, are you suggesting using D::P / D::P::N to do something like: my $dp = new D::P(...); $ht->param(pages_in_navigation => $dp->pages_in_navigation(...)); ? Then you would need to do some "prorgamming" in your template to get the values into something printable - which may be not in the spirit of H::T. When I created my pager, I emitted template variables into a global hash which eventually got set into the H::T->param() using a template variable "prefix" so that I could use multiple paginations in a single H::T output. Looking at D::P's API it would appear that some shim code needs to do something similar (ie: something like a H::T::DP ) with an API that looks a bit like: $ht = new H::T(..) $dp = new D::P(...); ... H::T::DP->publish( $ht, $dp, prefix => "pager_"); ... $ht->output(); >> What is the problem you are trying to solve? Someone here might have >> solved it already... >> > > I hope this gives enough info. If I'm doing it wrong, I'm only too > pleased to be told if there's a better way. Michael Peters suggested > Javascript as one solution, although I'd prefer a solution in H::T if > possible. I have looked through the docs, and couldn't see anything > obvious, but was hoping that perhaps someone had solved this problem > before me via some kind of logic that I hadn't thought of. > One problem with a javascript solution is that it makes localisation more complex - still do-able, but easier on the server side as your javascript would have to be aware of whether "4 stars" and "stars 4" is the correct ordering (ie: where "stars 4" would be the in some other langauge where the number comes after the description). [ There are already some Perl modules capable of this type of localisation complexity - implementing it Javascript would be possible, but I'm not sure if it would be worthwhile. ] Mathew |