Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8458275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:01:59+00:00 2026-06-10T13:01:59+00:00

I am porting a plain HTML/CSS/JS site to using Sinatra for its backend. The

  • 0

I am porting a plain HTML/CSS/JS site to using Sinatra for its backend. The main thing I’m interested in is templates. For now, I have a views directory with HTML files named like “index.html.erb” and a layout named “layout.html.erb”. While I would like to use Sinatra’s templates with erb, the site I’m working on is static. In other words, my “index.html.erb” does nothave any erb-specific code in it. I only really need the layout in my views directory, for now.

Is there a way that I can move views/index.html.erb to public/index.html but still wrap it in the template views/layout.html?

require 'rubygems'
require 'sinatra'

get '/index.html' do
    @page_title = 'Home'
    @page_id = 'index.html'
    erb :'index.html', { :layout => :'layout.html' }
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:02:01+00:00Added an answer on June 10, 2026 at 1:02 pm

    Having read through the Sinatra Readme, there are two main issues that come up in what you are trying to do. First, static files versus template files: Sinatra doesn’t have a template renderer for plain HTML, so you’d have to use ERB. Since ERB can be plain HTML, the issue with this is that Sinatra can only use a certain list of file extensions for ERB (and .html isn’t one of them).

    The second issue is that, in your example code, you would have to have the layout folder different from the templates folder (which Sinatra sees as being the same, which is /views by default).

    With this in mind, the closest you could get to what you are asking is the following:

    require 'sinatra'
    
    configure do
      set :views, root
    end
    
    get '/index.html'
      erb :'public/index.html', { :layout => :'views/layout.html' }
    end
    

    However, this also has a few problems. First, as mentioned, you would have to name your files with the .html.erb extension (or, just .erb if you cut the .html out of the 7th line above). Additionally, anyone could access the raw template file at /index.html.erb on your server. Therefore, the method that you displayed in your original question is the best way to do what you are trying to do in Sinatra without delivering a plain HTML file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Porting an application from C# (1.1 framework) to VB.NET (3.5 framework), and I have
I'm porting a small Qt application to the Android . I am using Qt
I am currently porting an application from iOS into Android and I have ran
I have an old personal project written in Java 1.4 that I am porting
I have a code library written in plain old C++ (no .NET/managed code) and
I'm porting an application to Rails 3. We're an e-commerce site and naturally we
I can't seem to find a straight answer for this: I have a HTML
I would like to port an existing Linux application from its plain C/C++ source
I'm porting a class from plain JDBC to use Spring. Part of this class
I am using ASP.NET to process plain forms, posting back to myself. (I dont

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.