You are here

twig

Calculate a value from options field in Webform custom composite element with Twig - Drupal 8

Recently, I was creating an event registration Webform. I created a custom composite field with the fields needed for each registrant: first name, last name, and a set of three radio options for their organization status: member, non-member, membership fee included in event registration. Each status has a different registration fee.

I then wanted to create a computed Twig field that would calculate the total registration fee by getting the data from the chosen radio option for each attendee and adding it up. This proved surprisingly tricky.

Print formatted date with correct timezone from datetime or daterange field in node and Views templates - Drupal 8

I've been working on a site with events, and tearing my hair out over how to print formatted dates with the correct timezone value in Twig templates, specifically node.html.twig and views-view-fields.html.twig.

Add visually hidden file type indicator to file field links - Drupal 8

I'm working on a website which has icons on file upload links, like so:

PDF file links with icons

This is nice for people who can see the icons, but what about those who can't? Accessibility means giving all users an equivalent experience, regardless of how they're accessing the site.

If the icons were inline images, we could put an alt of "PDF" on them and be done. However, in this case, they're background images.