Is there a way to display a caption on the lightbox video gallery made using CMS.
Is possible to pull information from the cms to be included in the caption? I have followed the steps in this tutorial, but I have not been successful. How to Caption a Lightbox with Video
Hi @Tobin, unfortunately at this particular time, captions are not available on Lightbox using the CMS feature. I do know it will be coming soon, soon.
I know you can do it with a CDN and custom code. I have to see if I can get the link for you.
I know you can do it with a CDN and custom code. I have to see if I can get the link for you.
Hey Brandon,
If you have it to hand and it’s not too much trouble, that link would be really useful No worries if not though, particularly if the feature is already being actively worked on!
For anyone wishing to vote for this in the Wishlist, I have added it HERE.
I have the same issue and I almost have a solution.
I created a div/window that contained dynamic text getting the caption text from the CMS.
I set the display to none, then created an interaction that would show the caption text when I clicked on the lightbox button.
This is what it looks like when I open the video lightbox…
Hey I was able to solve this with some creative Javascript. Essentially, when you create a lightbox and tell it to use the images in the “Gallery” field of a given post, it renders a lightbox. The problem is that Webflow hasn’t implemented a way for you to add a caption to each of those images. I found a work-around:
Use the ALT tag on the image in your gallery as the place where you put the caption.
Inject a script tag in your page OUTSIDE of the lightbox that loops through each thumbnail and modifies the JSON in the tag that Webflow renders for each gallery image. My script is below, and it works to render the ALT attribute’s text into the caption of the full-screen image simply by adding the “caption” element to the JSON object of each tag.
SCRIPT:
/*
This script replaces each gallery thumbnail wrapper given its
classname which you MUST make unique to the page. I’ve used
.gallerythumbnail. Keep in mind that WF will render
them to lower case, so keep them lowercase in the WF editor
in order to avoid confusion.
The script loops over each thumbnail and finds its SCRIPT
tag which WF generates with some JSON you can attach a
caption value to. When a caption value exists, it will
render in the main view of the image in the lightbox.
*/
const DGCs = document.querySelectorAll(‘.gallerythumbnail’)
DGCs.forEach((thumb,i,a)=>{
const imageAltText = thumb.parentNode.querySelector(‘img’).alt
const script = thumb.parentNode.querySelector(‘script’)
const imageJSON = JSON.parse(script.innerHTML)
imageJSON.items[0].caption = imageAltText
script.innerHTML = JSON.stringify(imageJSON)
})
I am using this with images. I found this article, https://www.flowbase.co/blog/cms-lightbox.
I added the following line into the Items: object in the custom code, “caption”: “put here your caption field from your cms here”.
I did this buy copy and paste the url: line, dont forget the comma at end of url: line
Hello James, it seems you were able to make this work… Is there a chance i could pick your brain about the specifics? Please let me know. Thanks, Andras