Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Count Albums


Go to End
Reply


10 Posts   2143 Views

Avatar
redactuk

Community Member, 117 Posts

30 May 2010 at 1:18pm

In my templates is there a default way to test how many albums there are in a gallery?

Avatar
UncleCheese

Forum Moderator, 4096 Posts

30 May 2010 at 3:10pm

$Albums.Count doesn't work?

Avatar
redactuk

Community Member, 117 Posts

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 %>

Avatar
UncleCheese

Forum Moderator, 4096 Posts

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.

Avatar
redactuk

Community Member, 117 Posts

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?

Avatar
redactuk

Community Member, 117 Posts

6 June 2010 at 4:46am

Anyone?

Avatar
UncleCheese

Forum Moderator, 4096 Posts

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.

Avatar
redactuk

Community Member, 117 Posts

7 June 2010 at 3:00am

<% control SomeGalleryPage %>
<% if SingleAlbumView %>single album<% end_if %>

That solves my problem - thanks UC. I've made note to replace it with AlbumCount on later maintenance update.

Go to Top