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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Files as pages (using KickAssets) and how to set current state?


Go to End


1158 Views

Avatar
neilcreagh

Community Member, 136 Posts

25 April 2012 at 2:12am

Edited: 25/04/2012 2:14am

This info below might be useful to someone doing something similar, but just skip to the two questions below it if you like:

- - - - - -
I'm using Uncle Cheese's KickAssets module to add multiple Images to pages. Then I'm attempting to show them individually on the page with thumbnails and links to next/previous.

Using Kickassets the Photos are just files (as opposed to a new Dataobject)

static $many_many = array ( 
   'Photos' => 'File' 
   );

So I'm using the Datobjects as pages technique but instead of calling a data object I'm calling the File by its ID in the URL eg. /show/165
public function getPhoto() 
{ 
$Params = $this->getURLParams();

if(is_numeric($Params['ID']) && $Photo = DataObject::get_by_id('File', (int)$Params['ID'])) 
{ 
return $Photo; 
} 
}

This is working perfectly (after many failed attempts) - and in my template I can show the current photo using

<% control Photo %> 
<img src="$URL" alt="$Title" /> 
<% end_control %>

In order to show the thumbnails I call all the Photos belonging to this page:

public function ShowPhotos($limit = null) { 
   $data = $this->getManyManyComponents('Photos', '', 'ManyManySort', '', $limit); 
   return $data; 
   }

And on my template

<% control ShowPhotos %> 
<a href="$Top.URLSegment/show/$ID" id="$Top.Photo.ID"><img src="$URL" alt="$Title" /></a> 
<% end_control %>

So far so good (and the above might be useful to someone trying to do similar)

- - - - - -
Question 1
- - - - - -
But I'd like to know how to highlight the current thumbnail, because $LinkingMode won't work for files … essentially I need to do this

<% if ID=Top.Photo.ID %>class=current<% end_if %>

but this doesn't work - so how would I write that as a function I can call from inside this ShowPhotos control loop?

- - - - - -
Question 2
- - - - - -
What's the best way to call the next and previous file links?

Any suggestions or advise on this would be greatly appreciated, thanks.