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.

All other Modules /

Discuss all other Modules here.

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

Image uploads in seperate content div


Go to End


3 Posts   959 Views

Avatar
neilos

Community Member, 19 Posts

7 October 2010 at 5:34am

Sorry if its been done, but I couldn't find it.

What I have atm is a seperate tab for up to 6 images to be added on a page, but seperate from main content.
ArticlePage.ss

<div id="gallery">
      <a rel="lightbox" class="lightbox" href="$Photo.URL">$Photo.SetWidth(130)</a>
      <a rel="lightbox" class="lightbox" href="$Photo2.URL">$Photo2.SetWidth(130)</a>
      <a rel="lightbox" class="lightbox" href="$Photo3.URL">$Photo3.SetWidth(130)</a><br />
      <a rel="lightbox" class="lightbox" href="$Photo4.URL">$Photo4.SetWidth(130)</a>
      <a rel="lightbox" class="lightbox" href="$Photo5.URL">$Photo5.SetWidth(130)</a>
      <a rel="lightbox" class="lightbox" href="$Photo6.URL">$Photo6.SetWidth(130)</a>      
      </div>

What i can't figure out how to do is;

<div id="gallery">
<% if there is actually an image uploaded then display this %>
      <a rel="lightbox" class="lightbox" href="$Photo.URL">$Photo.SetWidth(130)</a>
<% end_if %>... etc for other images below.
      <a rel="lightbox" class="lightbox" href="$Photo2.URL">$Photo2.SetWidth(130)</a>
      <a rel="lightbox" class="lightbox" href="$Photo3.URL">$Photo3.SetWidth(130)</a><br />
      <a rel="lightbox" class="lightbox" href="$Photo4.URL">$Photo4.SetWidth(130)</a>
      <a rel="lightbox" class="lightbox" href="$Photo5.URL">$Photo5.SetWidth(130)</a>
      <a rel="lightbox" class="lightbox" href="$Photo6.URL">$Photo6.SetWidth(130)</a>      
      </div>

Right now it displays 6 images in lightbox regardless if 6 images have been uploaded or not.

Any ideas? I've been on this for a few hours alone.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

7 October 2010 at 7:06am

<% if Photo %>
<a rel="lightbox" class="lightbox" href="$Photo.URL">$Photo.SetWidth(130)</a>
<% end_if %>

<% if Photo2 %>
<a rel="lightbox" class="lightbox" href="$Photo2.URL">$Photo2.SetWidth(130)</a>
<% end_if %>

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
neilos

Community Member, 19 Posts

7 October 2010 at 8:21pm

Thanks UncleCheese, it is a privilege.

Sometimes solutions are far too simple.

Keep up the good work.