Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Exlude Default Album from Album list

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 706 Views
  • redactuk
    Avatar
    Community Member
    115 Posts

    Exlude Default Album from Album list Link to this post

    I've built a global menu for a new site that uses a separate unordered list for each top level section. So that I can have multiple albums per subject matter I have a top level container page called Gallery that holds 6 actual imgage_gallery galler pages, with each of these having X number of albums. The menu code I have that works ok so far is:

       <ul class="topNav">
          <li class="sub-li"><a class="sub-a" href="/gallery">Gallery</a>
             <ul>
             <% control ChildrenOf(gallery) %>
              <li class="sub-li"><a class="sub-a" href="$Link">$MenuTitle</a>
                 <% if Albums %>
                   <ul class="fly">
                   <% control Albums %>
                       <li><a href="$Link">$AlbumName</a></li>
                    <% end_control %>
                    </ul>
                 <% end_if %>
              </li>
             <% end_control %>
             </ul>
          </li>
       </ul>

    Now at the moment this displays a nice drop-down from Gallery of my 6 gallery pages. But of course the flyout level 3 is displaying 'Default Album' for each gallery. Is there some IF condition I can place in the <% control Albums %> loop to only output a list item if the album name is not 'Default Album'? I'm sure this can be done I'm just struggling with the syntax. Can anyone help?

    Thanks

  • redactuk
    Avatar
    Community Member
    115 Posts

    Re: Exlude Default Album from Album list Link to this post

    Well that was a non starter. Trying a different approach now, and that's to require that the Default Album in each gallery is given the same name as the Gallery holder page itself. So now I need something as simple as:

       <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 AlbumName != MenuTitle %>
                       <li><a href="$Link">$AlbumName</a></li>
                      <% end_if %>
                    <% end_control %>
                    </ul>
                 <% end_if %>
              </li>
             <% end_control %>
             </ul>
             <% end_if %>
          </li>
       </ul>

    Why does that bottom level comparison not work? I've spent over an hour searching for examples of anything similar on these forums but with no luck. Why is $Menutitle not available for a comparison with $AlbumName within this control loop?

    Any pointers would be appreciated.

    Thanks

  • UncleCheese
    Avatar
    4085 Posts

    Re: Exlude Default Album from Album list Link to this post

    You can't compare variables in SSViewer. Only literals.

    You could probably decorate your ImageGalleryAlbum class to have the function:

    public function IsDefault()
    {
    return $this->owner->AlbumName == $this->owner->ImageGalleryPage()->Title;
    }

    ... or just decorate it to have a checkbox for "Default" and then you don't have to deal with arbitrary naming conventions..

  • redactuk
    Avatar
    Community Member
    115 Posts

    Re: Exlude Default Album from Album list Link to this post

    Well the first option seems the least complicated, but I'm just not getting how to do this...

    I'ved created:

    class MyImageGalleryAlbum extends ImageGalleryAlbum
    {
       
       public function IsNotDefaultAlbum()
       {
          return $this->owner->AlbumName != $this->owner->ImageGalleryPage()->Title;
       }
       
    }

    I'm guessing that's incorrect?

    Note: I reversed condition as I can't seem to specify <% if Not(IsDefaultAlbum) %> or anything similar

  • UncleCheese
    Avatar
    4085 Posts

    Re: Exlude Default Album from Album list Link to this post

    Oh, ok, if you want to do it with a subclass, you can do that, too. Just make sure you subclass your imagegallery page, too, and add

    protected $albumClass = "YourAlbumClass";

    otherwise, it's

    YourAlbum extends DataObjectDecorator

    and DataObject::add_extension("ImageGalleryAlbum","YourAlbum");

    in your config somewhere..

    706 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.