Masonry Image Gallery

If you have Tiles installed on your site and want to switch to Masonry, you need to change the attribute of the gallery divs to data-masonry-gallery on all of your old gallery posts. That’s if you want your old gallery posts to still render correctly, but don’t want to have both components installed.

Thought I share how you could do that, since I made the switch on my own site. Maybe it can be of some help to someone.

The most obvious way would be to edit the posts manually. That works as long as you don’t have too many posts you need to change, though it could still be a pain to find every posts. But don’t worry, data explorer to the rescue! Run the following SQL and you’ll get exactly what you need.

SELECT user_id, topic_id, post_number
FROM posts p
WHERE raw ~~ '%data-theme-tiles%'

If there’s too many to edit manually, you could use rake to replace every string. To do that, you need to SSH into your sever and run:

cd /var/discourse
./launcher enter app
rake posts:remap["data-theme-tiles","data-masonry-gallery"]

You can read more about that solution on this post. Please note the warning from that post about the rake posts:remap command:

There are most likely also other ways to do it. For example, if you like to you could modify the components code so that it looks for both attributes.

5 Likes