ruedacal / razor-mediator-4-tridion

Automatically exported from code.google.com/p/razor-mediator-4-tridion
0 stars 0 forks source link

IsLast on a component presentations list doesn't work as expected #1

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I think I've found a problem with the way IsLast works on component 
presentations lists in version 1.2.

If you use the following code:

@foreach (var cp in GetComponentPresentationsByTemplate("General Article"))
{
    <div>@cp.IsFirst @cp.IsLast</div>
}

We should expect to see something along the lines of (dependent on the CPs on 
the page:

<div>True False</div>
<div>False False</div>
<div>False False</div>
<div>False True</div>

What we really see is (again, dependent on the CPs on the page):

<div>True False</div>
<div>False False</div>
<div>False False</div>
<div>False False</div>

After looking at the code (TridionRazorTemplate.cs) for 
GetComponentPresetationsBy*() we are setting IsLast within the loop and 
relative to the component presentations on the page rather than the current 
index in the returned list:

cpm.IsLast = cpm.Index == ComponentPresentations.Count - 1;

Not 100% and not tested anything but a fix may be to set the IsLast property 
once the loop is finished using the last item in the returned list rather than 
for each loop item.  Would removing the above line in the loop and using 
something like the following after the loop work?

componentPresentations.Last().IsLast = true;

Not a major problem as we can just use a variable for the counter but figured 
you may want to know either way.

Cheers,
Andy W

Original issue reported on code.google.com by a.whiteh...@building-blocks.com on 14 May 2012 at 2:56

GoogleCodeExporter commented 8 years ago

Original comment by alex@tahzoo.com on 11 Sep 2012 at 2:52

GoogleCodeExporter commented 8 years ago
Thanks Andy! Your fix has been put into the upcoming Razor Mediator version 1.3.

Original comment by alex@tahzoo.com on 14 Sep 2012 at 3:24