Default Header Image in posts


#1

How would I set up header image for every blog post on Casper2 as default one?

So - basically I want default image to show up for every post on which I didn’t set up any other image,
so that posts aren’t without image, but would have default one.


#2

Try

{{#unless feature_image}}
    <img src="path/to/img.jpg" alt="My default image" />
{{/unless}}

#3

This doesn’t work for me. :fearful:

I get "> displayed instead of image.


#4

Sounds like you might’ve typo’d/missed a quote mark


#5

Thank You very much, it works now. :slight_smile:


#6

just a little update on this one, in case it might come in handy to anyone in the future.

above code is great as starting point, but since featured image is in a div, this one must be as well,
otherwise it’s height is bigger, which disrupts nice look of blog cards.

    {{#unless feature_image}}
<div class="post-card-image" style="background-image: url(https://source.unsplash.com/daily)" alt="cover"></div>
    {{/unless}}

this is all in file called : post-cards.hbs

This could be also a nice official addition to Casper theme, now when I think about it.
But I’m not sure how would setting of background image by user be made possible.
Probably via Ghost’s admin panel.


#7
{{#if feature_image}}
<img src = "{{img_url feature_image}}" alt = "{{title}}"/>
{{else}}
<img src = "{{asset "path/to/default/img.jpg"}}" alt = "{{title}}"/>
{{/if}}

Hope this helps! :slight_smile: