Troubleshooting adding promotional images to an 11ty blog starter with Sanity
28 replies
Last updated: Jan 3, 2023
A
Hey all, I want to create a blog for my website (using Sanity + 11ty starter blog) however I run into some problems when I try to do the guides from the sanity blog.
Specifically when I am following what
the article suggests , I get these errors:
Specifically when I am following what
the article suggests , I get these errors:
Dec 31, 2022, 8:48 PM
A
I figured out that when I reference imageObject in here:
Jan 2, 2023, 7:25 AM
A
I realized that when I reference imageObject from the guide in post.njk I get the error. The same error happens if I replace imageObject with mainImage
<img src="{% imageUrlFor imageObject, 400 %}" alt="{{ post.mainImage.alt }}">
Jan 2, 2023, 7:27 AM
A
I realized that when I reference imageObject from the guide in post.njk I get the error. The same error happens if I replace imageObject with mainImage
Any pointers greatly appreciated
😄
<img src="{% imageUrlFor imageObject, 400 %}" alt="{{ post.mainImage.alt }}">
Any pointers greatly appreciated
😄
Jan 2, 2023, 7:28 AM
S
Hello
I know unanswered questions are frustrating, but please also understand that we all do our best.
Since you have a specific problem, you need to add specific questions. We cannot go through the whole guide and guess where you could have gone wrong.
So please, help me help you
😉
user H
you need to be more specific, about your setup. And please do not repost things so often in the channel. The reason you might not get an answer might be that a) its the holidays and people are not as active/working or your problem is not sufficiently explained. You need to provide some code or more explanations for people to be able to help.If you need any ideas on how to do so, I can recommend user F
blog article .I know unanswered questions are frustrating, but please also understand that we all do our best.
Since you have a specific problem, you need to add specific questions. We cannot go through the whole guide and guess where you could have gone wrong.
So please, help me help you
😉
Jan 2, 2023, 2:47 PM
A
Apologies Saskia, it was not my intention to repost constantly!
I am trying to follow a guide from Sanity (
https://www.sanity.io/guides/how-to-add-promotional-images-to-the-11ty-blog-starter ) however although I believe I follow everything correctly, I get an error I cannot seem to solve... It seems to be happening after I put this line of code in the post.njk:
If I remove the line above, the deploy has no errors
PS: I am a complete noob in coding, just googling a lot while trying to create a blog...
Hope the info is a bit more helpful, glad to provide more if I can
I am trying to follow a guide from Sanity (
https://www.sanity.io/guides/how-to-add-promotional-images-to-the-11ty-blog-starter ) however although I believe I follow everything correctly, I get an error I cannot seem to solve... It seems to be happening after I put this line of code in the post.njk:
<img src="{% imageUrlFor imageObject, 900 %}" alt="{{ post.mainImage.alt }}">
If I remove the line above, the deploy has no errors
PS: I am a complete noob in coding, just googling a lot while trying to create a blog...
Hope the info is a bit more helpful, glad to provide more if I can
Jan 2, 2023, 7:32 PM
S
no issue! just wanted you to stop 😉
And we all started somewhere, you came to the right place I think to get help as a noob! I started a couple of years ago and now …
And we all started somewhere, you came to the right place I think to get help as a noob! I started a couple of years ago and now …
Jan 2, 2023, 7:40 PM
S
.url()method in you urlForImage (the screenshot is from the js example, but you see, that this is missing
Your setup should be working..
https://www.sanity.io/guides/how-to-add-promotional-images-to-the-11ty-blog-starter#09bd0eafb249
Jan 2, 2023, 7:42 PM
S
Can you check how your image is called in the post schema?
Jan 2, 2023, 7:45 PM
S
because if it is mainImage using
post.mainImage?.assetinstead of imageObject should work
Jan 2, 2023, 7:45 PM
S
and can you test the output of the
urlForImage, so we know if this or the 11ty is the issue?
let image = imageUrlFor(post.mainImage.asset); console.log(image)
Jan 2, 2023, 7:55 PM
A
upon someone's recommendation I put this code in post.njk
I get this:
{{post.mainImage | dump }}
I get this:
{"_type":"mainImage","alt":"Mountains in cloudly weather with a beach.","asset":{"_ref":"image-9843381ae2f30b9a069c528928e100af8cf21f5e-2048x1024-jpg","_type":"reference"},"caption":"Inspiring photo of a Norwegian mountain view. Photo by Torbjorn Sandbakk."}
Jan 2, 2023, 8:54 PM
S
okay so you need to use mainImage in urlFor (or mainImage.asset)
Jan 2, 2023, 8:56 PM
A
post.mainImage.asset
Jan 2, 2023, 8:57 PM
A
I think it works like that!
Jan 2, 2023, 8:57 PM
S
jup exactly!
Jan 2, 2023, 8:57 PM
S
But the image name is mainImage thats a big step forward!
Jan 2, 2023, 8:58 PM
S
try both and report back 😉Sorry we barely use 11ty in our teams… but that should work
Jan 2, 2023, 8:58 PM
A
I tried mainImage without the .asset part and that did not work
Jan 2, 2023, 8:59 PM
A
post.mainImage works
Jan 2, 2023, 8:59 PM
A
and post.mainImage.asset works too
Jan 2, 2023, 8:59 PM
S
you wanted 1 solution … we have 2 now :cool_doge:
Jan 2, 2023, 9:00 PM
A
Thank you
user J
, again apologies for my eagerness to solve it, as inexperienced as I am it took me 3 days trying to figure it out. I even deleted the project 3 times and started all over againJan 2, 2023, 9:00 PM
S
you must have been really frustrated… Well we go it now 🤝
Jan 2, 2023, 9:01 PM
S
btw: we have an 11ty channel!
Jan 2, 2023, 10:35 PM
A
Oh thank you Saskia, btw, is it appropriate to ask in this thread/channel about some netlify deployment errors with this sanity-eleventy starter?
Jan 2, 2023, 10:41 PM
S
Sure! I will not answer today though :parrot_sleep:but some others might
😉
😉
Jan 2, 2023, 11:07 PM
S
But start a new thread please
Jan 2, 2023, 11:08 PM
A
Thank you!
Jan 3, 2023, 7:15 AM
Sanity– build remarkable experiences at scale
The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.