Jump to content

Appending HTML into a class

Recommended Posts

Site URL: https://bartlett-schenk.squarespace.com/

Hey,  I seem to be having an issue appending HTML into a blog section using Post Blog Item Code Injection.  What I have done is fetched the data and was looking to loop through each post and create a class to render onto the page but when I look on the console logs, it seems I am getting errors but had no issue getting the data previously.

This is the code which is also inserted in the code injection section for the main website


 

<script>  

	fetch("https://bartlett-schenk.squarespace.com/insights?format=json-pretty")
  		.then( response => response.json() )
  		.then((data) => {
      		let output = '';
      		Object.values(data.items).forEach( (post) => {
    			output += 
                  	`
						<div class="insight" style="background-image: url(${post.filename})">
						<h1>${post.categories[0]}</h1>
						<h3>${post.title}</h3>
						</div>
					`	
    		})
      		document.getElementsByClassName("BlogList").innerHTML = output;
        })
  
</script>

 

I have also attached the logs.

 

Screen Shot 2021-06-01 at 13.23.40.png

Link to comment
  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Posted Images

Create an account or sign in to comment

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


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.