3212 Posts in 847 Topics by 809 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2780 Views |
-
$FirstLast: what when the first is also the last?

13 February 2010 at 4:55am
People here probably know that within a control statement you can for example use class="$FirstLast" to add class="first" to the first item and class="last" to the last.
This might be nitpicking but what if the first is also the last? Right now it adds class="first" but shouldn't it add class="first last" or better class="firstlast". In that way you have more control over your layout with css.
I could probably create a function for this, but I just wanted to ask the people here their opinion.
-
Re: $FirstLast: what when the first is also the last?

15 February 2010 at 12:40pm
There is a method called FirstLast in the ViewableData.php:
/**
* Returns 'first' if this item is the first in the container set.
* Returns 'last' if this item is the last in the container set.
*/
function FirstLast() {
if($this->iteratorPos == 0) {
return "first";
} else if($this->iteratorPos == $this->iteratorTotalItems - 1) {
return "last";
} else {
return "";
}
}You could overwrite it in your Page class with further functionality
-
Re: $FirstLast: what when the first is also the last?

16 February 2010 at 1:14am
I know and I could. The only reason why I posted it here was to find out if there were other people who think this should be standard behavior.
-
Re: $FirstLast: what when the first is also the last?

16 February 2010 at 5:58am
You can use $First and $Last to achieve exactly what you want for styling purposes, so it's not really an issue of not having control over styling. If anything, "first last" might be more technically accurate (especially for javascript behaviours), but from a styling point of few it probably has as many issues as just "first".
-
Re: $FirstLast: what when the first is also the last?

16 February 2010 at 7:12am Last edited: 16 February 2010 7:14am
div {padding: 30px 0;}
div.first {padding-top: 0;}
div.last {padding-bottom: 0;}
div.first.last {padding-bottom: 0; padding-top: 0;}The last one might not even be necessary in this example, but the FirstLast function will probably return something like .firstlast and not .first.last
-
Re: $FirstLast: what when the first is also the last?

16 February 2010 at 8:01am Last edited: 16 February 2010 8:01am
Well, no, I would definitely not expect it to return "firstlast". I might expect it to return "first last", because the item is both a first item and a last item, but I would not want it to return a new, distinct, firstlast type (in which case, it would be better to call it a 'singleitem' or something meaningful). Makes no sense to require a whole new selector style that only applies to single items.
You are right, in your example div.first.last would not be required, but could be used to override styles from the previous selectors.
-
Re: $FirstLast: what when the first is also the last?

24 November 2010 at 9:26am
I recently asked myself this question. I noticed that $FirstLast would only return "first" when an item was both first and last.
I solved this by: class="$FirstLast <% if Last %>last<% end_if %>"
If the item in your control loop is both first and last this will return: class="first last" (note the space)
In your CSS both .first {} *and* .last {} classes will be applied.
-
Re: $FirstLast: what when the first is also the last?

15 February 2011 at 12:40am
Ran into the same problem, I would add my vote for changing the default behaviour to return 'first last', as this is more accurate and logical in my opinion.
| 2780 Views | ||
|
Page:
1
|
Go to Top |




