7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Count Albums
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 1563 Views |
-
Count Albums

30 May 2010 at 1:18pm
In my templates is there a default way to test how many albums there are in a gallery?
-
Re: Count Albums

31 May 2010 at 3:50am
What I'm trying to do on my website menu is test to to see if a gallery (I have many) has more than one album:
<ul class="topNav">
<li class="top p3"><a id="clients" class="top_link" href="/gallery">Gallery</a>
<% if ChildrenOf(gallery) %>
<ul class="sub">
<% control ChildrenOf(gallery) %>
<li><a href="$Link" class="fly">$MenuTitle</a>
<% if Albums %>
<ul>
<% control Albums %>
<% if IsNotDefaultAlbum %>
<li><a href="$Link">$AlbumName</a></li>
<% end_if %>
<% end_control %>
</ul>
<% end_if %>
</li>
<% end_control %>
</ul>
<% end_if %>
</li>
</ul>So ideally I need to replace the <% if Albums %> with an "if albums > 1"
The reason for this is I need to prevent a list being created where there is just one album, because where there is just one album this is NOT displayed as a result of my <% if IsNotDefaultAlbum %>
-
Re: Count Albums

1 June 2010 at 4:10pm
Have a look here:
See if any of these help, if what UncleCheese says doesn't help.
Cheers,
- Luke -
Re: Count Albums

2 June 2010 at 2:59am
I'm not sure that you can do a greater/less than comparison on the template level, unfortunately.
I would probably do:
<% if Albums.Count =1 %><% else %>Albums is greater than one<% end_if %>
Kind of cheesy, but since Albums.Count cannot equal zero, it should work.
-
Re: Count Albums

4 June 2010 at 12:14pm
Tried
<% if Albums.Count = 1 %>
or as I think it should be?
<% if Albums.Count == 1 %>
but it just reports error.
I've tested $Albums.Count and it is correctly evaluating, so why is this condition not being accepted?
-
Re: Count Albums

6 June 2010 at 6:07am
Because SSViewer sucks sometimes. Often times, you have exactly the correct syntax, but for whatever reason, the templating engine was never coded to understand certain combinations of code, e.g.
$Object.Property.Function(arg) never works
So it would seem that SSViewer can only evaluate <% if Property = Value %> and not <% if Object.Property = value %>
You might be inclined to just jump into a control, to avoid the dot syntax:
<% control Albums %>
<% if Count =1 %>But of course, a control on a DataObjectSet puts you in a loop, so that won't work.
Fortunately for you, there is a method on ImageGalleryPage called SingleAlbumView(), which returns true if the gallery has only one album.
<% control SomeGalleryPage %>
<% if SingleAlbumView %>single album<% end_if %>I've also added a method in the latest rev for AlbumCount(), so you should be able to do <% if AlbumCount = 3 %> in a ImageGalleryPage control.
| 1563 Views | ||
| Go to Top | Next > |


