How to include the alt text form field to the image block composer.php

I am creating a news area for a client that will use composer to create the news post pages. I have added the option for the client to add an image within the compose form but when this launches in the page composer I want the client to be able to add alt text for the selected image. I know I need to create a composer.php template and have tried various ways to get the alt text form field to appear but it is failing to output within the code.

An easy workaround is for the client to add the alt tag to the image once the page has been published and add it by incontext editing but it seems clumsy and to be honest, it should be a standard feature for the alt text form field to appear under the image select field to meet web accessibility standards.

Any advice would be appreciated.

I am not sure I understand what the problem is. Are you having difficulty providing your user a way to input the alt tag text in Composer? Or are you having difficulty outputting that text to the page within the image tag?

What I would do is create a page attribute and call it something like “alt tag text”. Then I would pull that into the page template and code it as the alt tag.

The issue you will have adding an alt tag to an image like you described would be that it would add it globally. Meaning if you want to add the image to another page with another alt tag it would overridden the other one.

My solution ties a alt tag to the page not the image.

Allowing the user to add an alt tag to the image in Composer. Example image attached…

Yes, I had considered an option like this. I would have to possibly create a template that removes the blank alt="" which gets generated with the image and then replace it with the ‘alt tag text’ page attribute as an alt tag instead.