<p>Generally speaking, only <a href="https://craftcms.com/classreference#craft.app.variables" rel="nofollow">Variable</a> classes are exposed to templates in Craft and there isn't a Variable wrapper for <a href="https://craftcms.com/classreference/helpers/DateTimeHelper" rel="nofollow">DateTimeHelper</a>.</p>

<p>However, that would be a super-simple <a href="https://craftcms.com/docs/plugins/introduction" rel="nofollow">plugin</a> to write that exposes <code>timeAgoInWords</code> as a Twig <a href="http://twig.sensiolabs.org/documentation" rel="nofollow">filter</a> so you could do something like</p>

<pre><code>entry.postDate|timeAgoInWords
</code></pre>

CC BY-SA 3.0
2015-12-31T18:06:09.110Z
2015-12-31T18:06:09.110Z
Brad Bell
<p>Not quite sure how to use functions defined in Helper classes in my templates. For example, trying to use "timeAgoInWords" on an entry's dateCreated attribute. I get an internal server error and a "Unknown "timeAgoInWords" function" message when I try to visit the page. It occurs to me that perhaps I have to include or import the DateTimeHelper class? I'm not sure how to go about this.</p>

<p>Here's a link to the Craft docs on the package that I'm trying to include:</p>

<p><a href="https://craftcms.com/classreference/helpers/DateTimeHelper" rel="nofollow">https://craftcms.com/classreference/helpers/DateTimeHelper</a></p>

<p>I'm trying to include the timeAgoInWords function in my index.html template within the templates folder.</p>

<p>Thanks a bunch!</p>

<error>
Issue trying to use function from DateTimeHelper class: "timeAgoInWords() is not defined"
# Issue trying to use function from DateTimeHelper class: "timeAgoInWords() is not defined"

(Asked by: username_0 on 2015-12-31)

Not quite sure how to use functions defined in Helper classes in my templates. For example, trying to use "timeAgoInWords" on an entry's dateCreated attribute. I get an internal server error and a "Unknown "timeAgoInWords" function" message when I try to visit the page. It occurs to me that perhaps I have to include or import the DateTimeHelper class? I'm not sure how to go about this.

Here's a link to the Craft docs on the package that I'm trying to include:

<https://craftcms.com/classreference/helpers/DateTimeHelper>

I'm trying to include the timeAgoInWords function in my index.html template within the templates folder.

Thanks a bunch!

**Tags:** error


---

## 1 answers

### Answer by username_1 on 2015-12-31. Score: 3 | Accepted answer

Generally speaking, only Variable classes are exposed to templates in Craft and there isn't a Variable wrapper for DateTimeHelper.
However, that would be a super-simple plugin to write that exposes timeAgoInWords as a Twig filter so you could do something like
entry.postDate|timeAgoInWords


---

