1

Unsure how to go about doing this. I'm looking to open a related entry in a modal on the same page. In an area, I have a list of houses. On click, I would like the user to open a modal and load the corresponding entry inside it.

Is there an easier way to do this other than AJAX loading it in?

2
  • Hey, are we talking front-end here?
    – dmatthams
    Mar 3 at 10:40
  • Yep. Can't see anywhere about loading Entries in a modal on a click etc.
    – JMKelley
    Mar 3 at 10:43
3

Ajax is probably the easiest way when using something like Fancybox:

<a data-fancybox data-type="ajax" data-src="yoursite.com/houses/house-slug" href="javascript:;">
    House page
</a>

If your house page has content you want to hide when viewed in the modal you can detect whether or not Ajax was used to request the page:

{% if not craft.app.request.isAjax %}
    Your header code
{% endif }

You could also just include the house content on the page, but hidden and use fancybox to reveal it. This is possibly more accessible.

2
  • For the Q/A, would it be possible to add integration without fancybox?
    – JMKelley
    Mar 3 at 11:18
  • For sure! Fancybox is a simple solution, but the principles would be the same if you were to custom code it.
    – dmatthams
    Mar 3 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.