<p>All the default field types are exposed as template <a href="http://twig.sensiolabs.org/doc/tags/macro.html" rel="nofollow noreferrer">macros</a> in <code>/craft/app/templates/_includes/forms.html</code>. Here's how you could easily create a DateTime input field:</p>

<pre><code>{% import '_includes/forms' as forms %}

{{ forms.date( {
    id : 'myDateField',
    name : 'myDateField',
    value : myDate | default
} ) }}
</code></pre>

<p>Note that for the date field, <code>value</code> needs to be a valid DateTime object.</p>

<p>Other input types – such as a plain text field – are created in a similar manner:</p>

<pre><code>{{ forms.text( {
    id: 'myTextField',
    name: 'myTextField',
    value : myValue | default,
    placeholder : 'My Placeholder',
} ) }}
</code></pre>

<p>Also note that as <code>_includes/forms</code> is outside the frontend <code>templates</code> folder, it will not be easily accessible outside the CP. If you want to include the form macros in a frontend template, see <a href="https://craftcms.stackexchange.com/a/4844/1098">the following SE thread</a> – I'm partial to Mike Pepper's answer, myself.</p>

CC BY-SA 3.0
2015-04-03T02:18:14.630Z
Fantastic! I figured there was a way other than copy/paste html.
Damon
CC BY-SA 3.0
2015-04-02T20:05:25.500Z
2015-04-02T20:05:25.500Z
2017-04-13T12:51:00.303Z
Mats Mikkel Rummelhoff
<p>I am just experimenting with plugin development and would like to use the existing <a href="http://buildwithcraft.com/docs/date-time-fields" rel="nofollow">dateTime field type</a>. For no other reason than to maintain consistency throughout my application.</p>

<p>Is there a way to call that field as a macro (for lack of better words) in my template or do I just view the generated source from one spot and copy/paste it into my templates?</p>

<p>Thank you!</p>

<plugin-development><fieldtypes>
Use default field type(s) within my plugin
# Use default field type(s) within my plugin

(Asked by: username_0 on 2015-04-02)

I am just experimenting with plugin development and would like to use the existing [dateTime field type](http://buildwithcraft.com/docs/date-time-fields). For no other reason than to maintain consistency throughout my application.

Is there a way to call that field as a macro (for lack of better words) in my template or do I just view the generated source from one spot and copy/paste it into my templates?

Thank you!

**Tags:** plugin-development, fieldtypes

---

## 1 answers

### Answer by username_1 on 2015-04-02. Score: 3 | Accepted answer

All the default field types are exposed as template macros in /craft/app/templates/_includes/forms.html. Here's how you could easily create a DateTime input field:
{% import '_includes/forms' as forms %}

{{ forms.date( {
    id : 'myDateField',
    name : 'myDateField',
    value : myDate | default
} ) }}

Note that for the date field, value needs to be a valid DateTime object.
Other input types – such as a plain text field – are created in a similar manner:
{{ forms.text( {
    id: 'myTextField',
    name: 'myTextField',
    value : myValue | default,
    placeholder : 'My Placeholder',
} ) }}

Also note that as _includes/forms is outside the frontend templates folder, it will not be easily accessible outside the CP. If you want to include the form macros in a frontend template, see the following SE thread – I'm partial to Mike Pepper's answer, myself.

> **Comments:**
> **username_0**: Fantastic! I figured there was a way other than copy/paste html.  

---

