HowTo overwrite Form.ss template

silverstripe-4
Tags: #<Tag:0x00007f10cfdc70f8>

#1

Silverstripe Version: 4.3

Question: I would like to overwrite the Form.ss template.
Where should it be placed?

I am using $default theme which was added with SS 4.x
See Custom Code Structure where
HTML with *.ss-extension for the $default theme are located within app/templates

The Form.ss template which is used by default is located within

vendor/silverstripe/framework/templates/SilverStripe/Forms/Includes/Form.ss

I tried already to overwrite the template using the following paths:

  • app/templates/Form.ss
  • app/templates/SilverStripe/Forms/Includes/Form.ss
  • app/templates/SilverStripe/Forms/Form.ss
  • app/templates/Includes/Form.ss

No success yet.

Does anybody know the location to be used to overwrite Form.ss?


#2

Hi @lhasselb

Try to put in themes/your-themes/ folder.

Hope this will help you.

Thanks!


#3

Thank you for the quick response.
I don’t use a theme here.
See SS4 docs :

By default only $default set is configured, which represents all module roots with a templates directory.

SilverStripe\View\SSViewer:
  themes:
    - '$default'

#4

Then there is default theme in themes folder that is simple put into themes/simple/templates/ folder.


#5

Thanks again. This will not help because
I don’t use a theme here (on purpose)

SilverStripe\View\SSViewer:
  themes:
    - '$public'
  #  - 'simple'
    - '$default'

So there is no meaning in adding the template to the non-used simple theme.


#6

Okay, I got your point, then please add that templates (i.e. templates/SilverStripe/Forms/Includes/Form.ss) folder into app/src folder.

Then please do dev/build?flush=all.

This may be help you.

Thanks


#7

Hey @lhasselb,

I tried this way i overwrite the UserForm.ss file and it works for me can see in this screenshot.

Screenshot%20from%202019-01-30%2016-24-50


#8

Thank you again @addwebsolution

as mentioned initially
I tried already
app/templates/Form.ss
app/templates/SilverStripe/Forms/Includes/Form.ss
app/templates/SilverStripe/Forms/Form.ss
app/templates/Includes/Form.ss

But I don’t get the last comment with the screenshot.
You are adding a template file and structure to the src folder which is meant for PHP implementation ?
How is the UserForm related to the Form.ss ?

I am lost…


#9

@lhasselb I am giving you just example of UserForm.

You tried with app/templates/SilverStripe/Forms/Includes/Form.ss structure, but please try with app/src/templates/SilverStripe/Forms/Includes/Form.ss structure.

And please let me know your view for the same.


#10

I moved
app/templates/SilverStripe/Forms/Includes/Form.ss
to
app/src/templates/SilverStripe/Forms/Includes/Form.ss
Did dev/build?flush=all .

No Success

SilverStripe\View\SSViewer:
  source_file_comments: true

still shows

<!-- template /Users/tommy/Sites/ss4/vendor/silverstripe/framework/templates/SilverStripe/Forms/Includes/Form.ss -->


#12

I did a dev/build?flush=all after every single change.

For

app/templates/Form.ss
app/templates/SilverStripe/Forms/Includes/Form.ss
app/templates/SilverStripe/Forms/Form.ss
app/templates/Includes/Form.ss

and now for

app/src/templates/SilverStripe/Forms/Includes/Form.ss

No success yet.


#11

Without moving into src folder did you tried dev/build?flush=all ?


#13

What’s the error you got in error log?


#14

There is no error?

No success yet means: The template is not overwritten.

The default template
<!-- template /Users/tommy/Sites/ss4/vendor/silverstripe/framework/templates/SilverStripe/Forms/Includes/Form.ss -->
is used.
And I want to overwrite that.


#15

I would have expected app/templates/SilverStripe/Forms/Includes/Form.ss to work.

You have this line in one of your config files?

SilverStripe\Core\Manifest\ModuleManifest:
  project: app

If this line is set to ‘mysite’ as per the old standard, your project templates probably won’t be mapped correctly.

There’s a page devoted to template inheritance here: https://docs.silverstripe.org/en/4/developer_guides/templates/template_inheritance/ (I find it a bit confusing though)


#16

Thank you for the response.

I have the mentioned line there

SilverStripe\Core\Manifest\ModuleManifest:
  project: app

And I also know the page about template inheritance.

Finally (after 4 hours debugging and manually cleaning the cache)

app/templates/SilverStripe/Forms/Includes/Form.ss

did the Job.