Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0
alicroft

Automatically display text when summary block is empty

Question

I've tried every solution I could find here on the Circle forum, but none are working!

page: https://theveil.squarespace.com/nfk
(scroll down to "Upcoming Events" section)

template: Royce

I've got a Summary Block displaying Events, filtered by Category. When nothing matches the filter criteria, there is just a big black space on the page. I'd prefer it to automatically display text when the summary block is empty, like

"There are no upcoming events at this location."

Note: The Upcoming Events section on the page is actually a page (/nfk-events) nestled within an Index Collection (/nfk), in case it matters.

Anyone have ideas / updates to the old solutions for this? (https://forum.squarespace.com/search/?&q=empty summary block&search_and_or=and&sortby=relevancy)

Screen Shot 2019-11-11 at 20.17.50.png

Edited by alicroft
add detail

Share this post


Link to post

7 answers to this question

Recommended Posts

  • 1

Hi @alicroft

The solution that I provided in March 2018 still works if the template doesn't use Ajax or if it is disabled.

It's an old answer, so if you have Ajax enabled, you'll need to replace the domready function with onInitialize instead:

<script>
window.Squarespace.onInitialize(Y, function(){ 
  var summaryExists = document.getElementsByClassName("summary-title")[0];
  if (summaryExists == null) { 
    document.getElementById('no-events').innerHTML = "There are no upcoming events at this location.";
  }
}); 
</script>

 


If a response has helped you, please give thanks using the  like-20-mag.png.3997345d620e40b4760b5d7a667cad54.png button.
Need personalised help? I'm a professional Developer who works with Designers internationally. You can book me via my company's website. www.sf.digital

Share this post


Link to post
  • 1

It will only work if you are logged on, or if you load that specific page. If you navigate from another page to that one, it won't. 

 


If a response has helped you, please give thanks using the  like-20-mag.png.3997345d620e40b4760b5d7a667cad54.png button.
Need personalised help? I'm a professional Developer who works with Designers internationally. You can book me via my company's website. www.sf.digital

Share this post


Link to post
  • 0

Thank you so much @paul2009, that worked perfectly!

For anyone else trying the same:

The script did not work in the page header injection (/nfk-events), but it did in the Index Collection header injection (/nfk).

Share this post


Link to post
  • 0

To be clear, the code won't work in the page header injection of either of these if you have Ajax enabled.

(Note that Ajax is never enabled when you are logged on to a site! This makes it appear to work whilst logged on, but as soon as you hand over a site and the client tries it, they'll find it doesn't work 😫

If further checks are added to the code to identify the collection or URL it can then be inserted in the Footer Injection and it will play nice with Ajax 🙂.


If a response has helped you, please give thanks using the  like-20-mag.png.3997345d620e40b4760b5d7a667cad54.png button.
Need personalised help? I'm a professional Developer who works with Designers internationally. You can book me via my company's website. www.sf.digital

Share this post


Link to post
  • 0

@paul2009 I have Ajax enabled, and inserted your code as written above into the Collection's header injection, and it's working...!

Is this delicate in some way? (I know nothing about Ajax or javascript!) Should I move it into the Footer Injection area of the site instead? I'd prefer to leave it on the Collection so I can customize what it says for each summary block on the site, if possible.

Share this post


Link to post
  • 0

I wrote a guide that may help you to understand how Ajax affects JavaScript on Squarespace:

https://sf.digital/squarespace-solutions/why-doesnt-my-code-work-until-i-refresh-the-page


If a response has helped you, please give thanks using the  like-20-mag.png.3997345d620e40b4760b5d7a667cad54.png button.
Need personalised help? I'm a professional Developer who works with Designers internationally. You can book me via my company's website. www.sf.digital

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...