Message Boards

Modifying SOY templates

Marcin Pawluk, modified 3 Years ago.

Modifying SOY templates

New Member Posts: 16 Join Date: 1/22/20 Recent Posts
I'm coming with another topic. We need to override SOY templates to fix some issues in Forms module. What we want to achieve is to connect labels with inputs (what is required by WCAG). I was searching forum and Liferay's documentation, but only found how to create SOY portlet -> https://help.liferay.com/hc/en-us/articles/360018159531-Creating-a-Soy-Portlet-. Is there any example how to override files with soy extentesion?As an example I will use https://github.com/liferay/liferay-portal/blob/7.2.1-ga2/modules/apps/dynamic-data-mapping/dynamic-data-mapping-form-field-type/src/main/resources/META-INF/resources/FieldBase/FieldBase.soy. We need to associate labels with their elements. Now generated field in form looks as below
<div class="form-group" data-field-name="_com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet_INSTANCE_iuOQgE90XKZb_ddm$$TextField$rxnY4qW2$0$$en_US"><label>Text Field </label><input class="ddm-field-text form-control" name="_com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet_INSTANCE_iuOQgE90XKZb_ddm$$TextField$rxnY4qW2$0$$en_US" type="text" data-oninput="null" data-onfocus="null" data-onblur="null" value=""></div>
WCAG validator requires to assign label with input. In Liferay 7.2.1 and 7.3.0 it's not correct.
thumbnail
David H Nebinger, modified 3 Years ago.

RE: Modifying SOY templates

Liferay Legend Posts: 14916 Join Date: 9/2/06 Recent Posts
So first, have you reported the issue on issues.liferay.com? To get a product fix, the report has to start there.

There is no supported way to change soy templates. JSP fragment bundles don't work because, well, soy templates are not JSP files.

The only solution is to build an override module. There are two options that I know of here, one that Olaf wrote about https://liferay.dev/blogs/-/blogs/maintainable-plugins-challenge and one that I wrote about https://liferay.dev/blogs/-/blogs/extending-liferay-osgi-modules


In each of these cases, you weave override files that you have with the Liferay original module, coming up with a modified module that goes into the osgi/marketplace/override folder.
Michał Janusz, modified 3 Years ago.

RE: Modifying SOY templates

New Member Posts: 14 Join Date: 3/8/16 Recent Posts
Hello David,
Thanks for your answer. I have a follow-up question about connecting labels and form fields using for/id HTML attributes.
In SOY template https://github.com/liferay/liferay-portal/blob/7.2.1-ga2/modules/apps/dynamic-data-mapping/dynamic-data-mapping-form-field-type/src/main/resources/META-INF/resources/FieldBase/FieldBase.soy
There is attributes assigment for label:
<label {$attributeslabel}></label>
But there is no "for" attribute and neither there is "id" of the field that this label is generated for. Can you give me some tips where in Liferay code this list of attributes is generated and injected into the template? And how can I add missing attributes?
Regards,
Michal
Marcin Pawluk, modified 3 Years ago.

RE: Modifying SOY templates

New Member Posts: 16 Join Date: 1/22/20 Recent Posts
Yes, I have reported issue -> https://issues.liferay.com/browse/LPS-114123. I will try your solutions (I hope it will help).
Burress Shawna, modified 3 Years ago.

RE: Modifying SOY templates

New Member Posts: 2 Join Date: 5/13/20 Recent Posts
One of the solutions posted above worked for me. You can try it too. It would help https://www.mybpcreditcard.us/