Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to wrap in <abbr> tag #60

Open
tomhv opened this issue Jun 4, 2015 · 2 comments

Comments

@tomhv
Copy link

commented Jun 4, 2015

Hey guys,

Do you think it would be possible to have the ability to wrap the time diff in an <abbr> tag?

So, something like

We shipped your order {{ order.shippedAt|ago }}.

would produce:

We shipped your order <abbr title="2015-03-04 10:00:00">2 months ago</abbr>

Not sure if this would be controlled by config or if there'd be a separate filter (ago_abbr).

Let me know what you think.

Cheers,

Tom

@tomhv

This comment has been minimized.

Copy link
Author

commented Jun 4, 2015

For now, I've extended the TimeHelper, but I still wonder if it is worth adding as a config item.

<?php

namespace Acme\Bundle\Templating\Helper;

use Knp\Bundle\TimeBundle\Templating\Helper\TimeHelper as BaseTimeHelper;

class TimeHelper extends BaseTimeHelper
{
    /**
     * {@InheritDoc}
     *
     * @param  mixed $since The datetime for which the diff will be calculated
     * @param  mixed $since The datetime from which the diff will be calculated
     *
     * @return string
     */
    public function diff($from, $to = null)
    {
        $from = $this->getDatetimeObject($from);
        $to = $this->getDatetimeObject($to);

        return sprintf(
            '<abbr title="%s">%s</abbr>',
            $from->format('Y-m-d H:i:s T'),
            $this->formatter->formatDiff($from, $to)
        );
    }
}

in parameters.yml:

parameters:
    # ...
    time.templating.helper.time.class: Acme\Bundle\Templating\Helper\TimeHelper
@pilot

This comment has been minimized.

Copy link
Contributor

commented Jun 5, 2015

yes you made correct or even you can extend datetimeformatter https://github.com/KnpLabs/KnpTimeBundle/blob/master/DateTimeFormatter.php#L80

as well feel free move out of the core the time template line to make ability manage it from the configuration, like we did it in the KnpMenuBundle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.