I'm calling user photo's from my template, but it error's out when trying to obviously call a user photo which is empty. What I'm trying to achieve is

if there is no user photo, use the default placeholder image craft supplies

The problem I'm having trouble getting to the bottom of is, how to access the default user photo?

    <img class="img-fluid rounded-circle" src="{{ entry.author.getPhoto().url }}" width="100" height="100" alt="{{ entry.author }} Picture">

Any help would be great


You want to use the default blank user SVG from the Control Panel on the front-end of the site when there is no photo selected?

If so, it's probably easiest just to copy it from vendor/craftcms/cms/web/assets/cp/dist/images/user.svg to a place in your public HTML folder and reference it there.

Something like:

{% if entry.author.getPhoto() %}
    {{ entry.author.getPhoto().url }}
{% else %}
    {{ url('path/to/user.svg') }}
{% endif %}

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.