Currently the available options for "Caption" under the display options for Colorbox are "Automatic, Title text, Alt text, No title, None". Placeholder tokens would allow for ultimate control, e.g. "[node:title] - [node:field-url]". I am aware of the views colorbox trigger field, but this would be a much more practical and simplistic option in my opinion.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

frjo’s picture

Assigned: Unassigned » frjo
FileSize
3.12 KB

I have been meaning to add this but never got around to it. Thanks for reminding me!

Please try the attach patch and report back your results here.

benmalen’s picture

Thank you so much, frjo! I applied the patch and it works great.

I have one problem however, as I want to show an actual URL in the caption but the tokens are stripped of all HTML.

For example, currently it will output something like this:

<a rel="gallery-21" class="..." title="Test - link" href="...">
<img title="" alt="" src="..." />
</a>

I want to output with encoded HTML like this:

<a rel="gallery-21" class="..." title="Test - &lt;a href=&quot;http://www.example.com/&quot;&gt;link&lt;/a&gt;" href="...">
<img title="" alt="" src="..." />
</a>

I had a go at making modifications, but unfortunately I am a bit rusty on the development side so it did not work out. I hope you may be able to help me with this.

kaylsbeth’s picture

I also applied the patch, frijo, and it worked beautifully! Thank you!

frjo’s picture

Status: Active » Fixed

Committed to 7-dev.

@benmalen, I don't believe HTML is allowed inside the title attribute. That’s why Drupal l() function that colorbox use to build link strips it out.

benmalen’s picture

Hmm, I used to use Lightbox and you could use HTML in the caption so I was hoping this could be done with Colorbox.
http://www.huddletogether.com/projects/lightbox2/

Can I insert links in the caption?
Yes, but you need to convert quotes and greater and less than symbols into their html entity equivalents. For example:
<a href="images/image-4.jpg" rel="lightbox" title="&lt;a href=&quot;link.html&quot;&gt;my link&lt;/a&gt;">Image</a>

I guess I can make do without. Thanks again.

andypost’s picture

Status: Fixed » Needs work
+++ b/colorbox.theme.incundefined
@@ -60,6 +60,14 @@ function theme_colorbox_image_formatter($variables) {
       break;
+    case 'custom':
+      if (module_exists('token')) {
+        $caption = token_replace($settings['colorbox_caption_custom'], array('node' => $node));
+      }
+      else {
+        $caption = $settings['colorbox_caption_custom'];
+      }
+      break;
   }

token_replace() is a core's function, so there's no dependency on token module. Field settings could be stored in-code or provided with features module. Token is useful when you editing setting.

Code should be:

case 'custom':
  $caption = token_replace($settings['colorbox_caption_custom'], array('node' => $node));
  break;
andypost’s picture

Status: Needs work » Needs review
FileSize
641 bytes

I mean this! Only settings are depends on token module

frjo’s picture

Status: Needs review » Fixed

Thanks for catching my mistake andypost, committed the fix to 7-dev now.

kaylsbeth’s picture

So, here's a question stemming, I think, from the tokens. I want to create a space for lengthier captions to exist using these tokens... in theory I could do this with title, but it's not long enough. How can I tie something up with each separate image that I could then use the tokens to implement? IE a separate caption field for each image. When Image wasn't tied up with the core in 6, this might have been a bit easier... I'm just hoping I won't have to create a new content type to try and get this to work.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.