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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Exlude Default Album from Album list


Go to End


5 Posts   1103 Views

Avatar
redactuk

Community Member, 117 Posts

18 April 2010 at 1:37am

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

Avatar
redactuk

Community Member, 117 Posts

20 April 2010 at 9:12am

Edited: 20/04/2010 9:16am

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

20 April 2010 at 9:22am

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

Avatar
redactuk

Community Member, 117 Posts

20 April 2010 at 10:26am

Edited: 20/04/2010 10:28am

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

20 April 2010 at 11:31am

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