Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[Solved] Form fields won't render with custom template


Go to End


2114 Views

Avatar
Landrade

Community Member, 1 Post

10 September 2016 at 11:05am

Edited: 15/09/2016 3:06am

Hi,
I've been having some trouble trying to render a form field with my own custom template. I followed the instructions provided here: https://docs.silverstripe.org/en/3.4/developer_guides/forms/form_templates/
However, when I try to set a template for a text field or for a field holder, it just uses the default templates.
This is what I've done:

$title_field = new TextField('title', 'Title*');
$title_field->setTemplate('my-text-field');

I made sure to add my templates to mysite/templates/Includes, and I even moved it around within the themes folder of our theme. However, none of that seems to work and it always ends up using the default template. Any help would be deeply appreciated.
---------------------------
I found the solution to my issue. From the looks of it, the file path the link tells you to store your templates in (mysite/templates/Includes/) doesn't seem to be recognized. Instead, the path has to be similar to how the default templates are saved in the framework. For example, the form templates I made had to be saved under mysite/templates/forms/ in order to be recognized by SilverStripe. Not sure if this is an issue or if the documentation isn't updated, but this is what I did to get my templates to render.