Tokens should allow to not output <time> element.

Created on 28 February 2024, 10 months ago
Updated 27 April 2024, 8 months ago

Problem/Motivation

When using Smart Dates if you want to use the token to output a date in some plain text email it comes across looking wrong because it has HTML in it. I think it'd be nice to be able to add :plain or something, whatever is best practice, to output the same token but strip out the HTML.

If you give me direction on which method you think is best I'd gladly get that worked out for you and submit a PR.

Steps to reproduce

In my usage I'm using ECA β†’ which on a cron send out reminder emails, but really anyway you can get an email to send while pulling an item with a date should work to recreate.

The token usage is:

Please don't forget to show up to the event [event:title] on [event:field_dates].

The outputted email will look like:

Please don't forget to show up, to the event My Test Event on <time datetime="2024-02-29T10:00:00-06:00" class="datetime">Thu, Feb 29 2024, 10</time>
 - <time datetime="2024-02-29T11:00:00-06:00" class="datetime">11 am</time>.

Proposed resolution

Like mentioned above, I think allowing someone to specify they don't want the markup would be easiest, I don't assume there is anyway to detect this is going to be used in a plain text format and output different.

I think if we added a new token that was :FORMAT:plain we could then use a new method on smart_date/src/SmartDateTrait.php:formatSmartDate that just calls formatSmartDate but then strips out the tags and returns as plain text. To me that seems like the absolute easiest option but there is probably a more elegant option which might be better considering the scope of this module.

Remaining tasks

Decide if this is a feature you want to add, or if there's a better way to solve this issue.

User interface changes

Not sure.

API changes

Not sure.

Data model changes

Not sure.

✨ Feature request
Status

Active

Version

4.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States josh.fabean

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @josh.fabean
  • πŸ‡¨πŸ‡¦Canada mandclu

    Hmmm, looking at the tokens you're using, it seems as though you're using the default tokens (not specific to Smart Date), so it's formatting those according to the default view mode for your content type. Theoretically you should be able to update the view mode to remove the markup.

    Additionally, you could use one of the tokens provided by Smart Date β†’ , which look like they're designed to return strings by default.

Production build 0.71.5 2024