My first question here... maybe one of a few! I've inherited a Craft project recently and don't have much experience with it.

I want to allow admin to set a border (and border color) whenever they add an image. Currently, the image field has a field type of Assets. I don't want to change the field type (to a Super Table or similar) because the component is used in so many other places - it would break.

We're using Craft 2 but upgrading to 3 presently.

Has anyone else had to do this before? Any suggestions on how to approach this? Let me know if I can clarify anything.

enter image description here


It looks like you're using a Matrix block with a field inside a block called Image. Given that information, I'd add a new field to that block called Border. You could either use a colour field, or a dropdown to set your own values. Then maybe something like this on the front end:

{% if block.image|length %}
<img src="{{ block.image.one.url }}" {% if block.border|length %} class="bordered border-{{ block.border }}"{% endif %}>
{% endif %}

Craft doesn't have any relation to the front end of your site intrinsically, so you could call the field whatever you like.

  • Ahh, yes - I'd totally missed that I could do that. Thanks Daryl. – carljwood Aug 15 '18 at 11:38

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.