0
votes

I'm new to rails and I've set up a standard spree e commerce solution. I now want to customize the default templates and styles. According to the spree documentation [1], the best way to do so is using Deface. Unfortunately, I can't figure out the location of the existing views/layouts.

For example, while the document suggests:

For example, to override the main layout, create the file YOUR_SITE_OR_EXTENSION/app/views/spree/layouts/spree_application.html.erb

my app/views folder doesn't contain a folder called spree

Can anybody tell me, how to change the view templates?

Thank you.

[1] https://guides.spreecommerce.com/developer/view.html

2
have you tried just creating that directory? - Taryn East
I just did, but no effect even after restarting the ruby application :( - Ronin
so you've added an application layout in the location above, with the above name - and with different content (so you know it's working or not) and it isn't using the other layout? - Taryn East
I now also tried to insert the layout spree_application.html.erb without adding content. My main page is blank now. So it seems to work. But my actual question is, where can I find the original layout pages in order to change them? Also, if I just edit the layout file, it will completely change. But I think it'd be a better idea to use Deface, so the original layout pages don't need to be changed. - Ronin

2 Answers

0
votes

You have to actually create that directory and every directory along the way until you reach the file you wish to override. If you run these commands from your root directory you should be good to go.

mkdir app/views/spree
mkdir app/views/spree/layouts
touch app/views/spree/layouts/application.html.erb

Then copy the content from here: https://github.com/spree/spree/blob/master/frontend/app/views/spree/layouts/spree_application.html.erb into the file you've just created.

If you restart your web server you should be able to make changes to the local application.html.erb file and see them locally.

Any time you want to override a template completely, you can find the template you need to override on Github: https://github.com/spree/spree and recreate the necessary files/directories. Spree will look for templates in on localhost before the gem, so as long as you override the right template in the right directory, you can customize any view you like.

0
votes

Alternatively, you can try running the rails generate spree:frontend:copy_views command to pull all the views you need from gems, and anything that is missing can be added manually, in strict accordance with the gems folder hierarchy. For example, in gems is parsl in the following spree_backend/views/spree/admin/users/_lifetime_stats.html.erb. To enter the desired code, I have to make a folder on the following path - the name of the project/app/views/spree/admin/users/_lifetime_stats.html.the erb and all the changes I will make here will fall into the main view code. This is an alternative to Deface::override