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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Custom form field template


Go to End


3 Posts   902 Views

Avatar
jpmcc

Community Member, 20 Posts

20 May 2015 at 12:14am

Hi,

Just trying to set a custom template for a TextField. It seems that you can specify a custom template, along the lines of:

TextField::create('MyTextField')->setTitle('My Field')->setTemplate('MyCustomTextFieldTemplate');

Where I have MyCustomTextFieldTemplate.ss in themes/mytheme/templates/formfields/MyCustomTextFieldTempate.ss.

Now, as far as I can determine, this will never be used. I get as far as

TemplateManifest::getCandidateTemplate()

In here it actually locates my custom template as part of the theme. However, it states in comments that any of the other potential templates that are found in the project will trump the theme. Fair enough. However, just at the end of that method when it has my template in the $found array, it works through the array and removes any templates it found in the theme or project and returns an empty array.

So, essentially, it is working at locating the custom array in the theme - finds it - then just throws away any templates it found in both theme and project.

Is there a point to that?

Version is 3.1.12

Avatar
Pyromanik

Community Member, 419 Posts

20 May 2015 at 4:33am

Edited: 20/05/2015 4:34am

Seems like a bug to me.

What it means by project trumping theme is that (going with project being 'mysite'):
1. mysite/templates are used
2. theme templates are used
3. module templates are used
4. core templates are used
5. error is thrown

Being that 4 is being favoured over 2, this I would deem a bug.

I knocked up a quick test in 3.1.6 and had the same issue.

Avatar
jpmcc

Community Member, 20 Posts

4 September 2015 at 11:17pm

Thanks for checking and confirming it seems to be an issue. Apologies for the radio silence, I thought by starting the thread I'd be automatically subscribed, but I guess not, so only checked back on this now.