About the author

Steven Harmansteven harman :: makes sweet software with computers!

For recent posts and more about me, scroll to the bottom.

Subscribe

  • Subscribe to my feed. via RSS
  • Subscribe via email via email

News

Badges

  • Subtext Project
  • Support Subtext

Lightbox and Subtext Galleries Integration

Recently several Subtext users have asked how to integrate Lightbox JS into Subtext's photo galleries. My standard answer has been

Right now it's not possible because the control that renders the galleries emits links with relative URLs rather than fully qualified URLs. We'll look into making a change to the data binding mechanism for a future release - so hold tight!

I finally had a few spare cycles so I looked into the existing data binding logic and realized that it is possible to get the control to emit fully qualified URLs right now! Notice, I said it's possible, but I didn't say it's elegant.

How it works now

You'll need to edit your skin's GalleryThumbNail.ascx control. This control renders the thumbnail images for a given gallery using a simple asp:DataList control. The controller (code) that handles the GalleryThumbNail.ascx control looks for an asp:HyperLink control inside the DataList. It then populates the HyperLink with an ImageUrl, NavigationUrl, and ToolTip for each image in the gallery.

So your skin control probably looks like this:

<asp:DataList id="ThumbNails" runat="server" OnItemCreated="ImageCreated"
  RepeatColumns="4" RepeatDirection="Horizontal">
  <ItemTemplate>
    <asp:HyperLink Runat="server" ID="ThumbNailImage" CssClass="ThumbNail" />
  </ItemTemplate>
</asp:DataList>

Hack it to work now

<asp:DataList id="ThumbNails" runat="server"
  RepeatColumns="4" RepeatDirection="Horizontal">
    <ItemTemplate>
      <div class="thumbnail">
        <a href="<%# BaseImagePath + 
        ((Image) Container.DataItem).ResizedFile %>" 
        title="<%# ((Image) Container.DataItem).Title %>" 
        rel="lightbox[<%# ((Image) Container.DataItem).CategoryID %>]">
          <img src="<%# BaseImagePath + 
          ((Image) Container.DataItem).ThumbNailFile %>" 
          alt="<%# ((Image) Container.DataItem).Title %>" />    
      </a>
    </div>
  </ItemTemplate>
</asp:DataList>

NOTE: For brevity and to make it fit on the page, I've shortened the above code. You'll need to expand each of the five Image casts to use the fully qualified class name, Subtext.Framework.Components.Image.

Coming to a Subtext Installation Near You

I've made some changes for the next version of Subtext (the recently announced v1.9.6) that will make the data binding expressions a bit more concise and easier to read. So starting with the next release you'll be able to do this

<asp:DataList id="ThumbNails" runat="server"
  RepeatColumns="4" RepeatDirection="Horizontal">
    <ItemTemplate>
      <div class="thumbnail">
        <a href="<%# BaseImagePath + 
        EvalImage(Container.DataItem).ResizedFile %>" 
        title="<%# EvalImage(Container.DataItem).Title %>" 
        rel="lightbox[<%# EvalImage(Container.DataItem).CategoryID %>]">
          <img src="<%# BaseImagePath + 
          EvalImage(Container.DataItem).ThumbNailFile %>" 
          alt="<%# EvalImage(Container.DataItem).Title %>" />    
      </a>
    </div>
  </ItemTemplate>
</asp:DataList>

I'll play around with the controller some more to see if we can make the code even more expressive - but no promises!

See it in action!

You can see the Lightbox2 and Subtext Galleries integration in action in my galleries. Check this one out: On the Town...

What others are saying.

# re: Lightbox and Subtext Galleries Integration
Gravatar Simon Philp
Jun 25, 2007
Nice easy change if your not confident in changing the source code :)

I started writing a new gallery control that gave the blog author the option to "bypass image page" if that makes sense. If true would add the rel="lightbox[Gallery Name]".

I hope to put in some more time with subtext.

Have kicked it as i think it's a valuable resource.

Si

# Lightbox and Subtext Galleries Integration
Gravatar DotNetKicks.com
Jun 25, 2007
You've been kicked (a good thing) - Trackback from DotNetKicks.com
# Popup Posts
Popup Posts
# re: Lightbox and Subtext Galleries Integration
Gravatar pex
Jul 10, 2007
hi, i have another problem with photogallery...my site is in second level domain host and when i create a gallery subtext make the link as first livel.
Example:
<img src="mydomain.com/mypic.jpg"> -> now..but don't work
<img src="www.mydomain.com/mypic.jpg"> -> what i need but i don't know how do...
sorry for my bad english...
# re: Lightbox and Subtext Galleries Integration
Gravatar Adrian
Aug 13, 2007
Thanks, that works super.
Comments have been closed on this topic.