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 8807055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:16:51+00:00 2026-06-14T02:16:51+00:00

I have a sinatra app that is mostly using erb for templates, but I

  • 0

I have a sinatra app that is mostly using erb for templates, but I am adding some mustache partials for blocks of html that need to be rendered on both the server and client side. I have a “views” directory where I’m keeping all my templates, including the mustache templates I’m adding. For example, the structure looks something like this:

views/
    index.html.erb
    _wingding.html.erb
    _widget.html.mustache

Let’s say I’m rendering index.html.erb using this endpoint:

get '/' do
    erb :index
end

And inside that template, I want to render both of the above partials [UPDATE: it turns out this partial method is not built into sinatra, but is included via a gem (see my answer for details), but it still relies on the main sinatra rendering component, so the problem here still stands.]. So index.html.erb contains:

<%= partial :wingding %>
<%= partial :widget %>

The erb partial (wingding) renders fine, but the mustache partial (widget) does not. It causes the application to throw an exception:

Template engine not found: mustache

I have included the ‘mustache’ gem in the project. I tried 'require mustache/sinatra' and register Mustache::Sinatra. Both of these statements worked, but didn’t solve the problem above. Any idea how to tell sinatra about mustache so that it can render mustache partials?

I’m setting my views directory by including this configuration:

configure do
    set :views, File.join(File.dirname(__FILE__), 'views')
end

Version numbers:

  • sinatra 1.3.1
  • mustache 0.99.4
  • ruby 1.9.3
  • 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-14T02:16:52+00:00Added an answer on June 14, 2026 at 2:16 am

    So it turns out the gem listed in the solution in my other answer caches output, meaning you can’t use it to include the same partial with different locals in the same request, which makes it worthless for my purposes. So here’s another (admittedly hackish) solution that I’ve settled on. I created a helper that will just deliver the contents of a given view:

    helpers do
        def template_contents(path)
            File.open("#{settings.views}/#{path}") { |f| f.read }
        end
    end
    

    Then, I just do a regular Mustache#render:

    <%= Mustache.render(template_contents('_widget.html.mustache'), { ... }) %>
    

    This works great for my use case.

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

Sidebar

Related Questions

I have a Sinatra app that basically takes some input values and then finds
I have a simple Sinatra app that I am playing with, and for some
I have a small Sinatra app that uses Twitter OAuth for authentication. Some time
I am using inline haml templates in my sinatra app. I have a @@layout
I have a simple Sinatra app that is configured using the modular style. When
I have a portfolio web app that is run on Sinatra using pjax .
I have a Sinatra app that I run as a daemon, using Apache port-forwarding
I have a Sinatra app that, boiled down, looks basically like this: class MyApp
I have a Sinatra app, that uses omniauth which constantantly gets this error attack
I have a Sinatra DataMapper app hitting a sqlite3 database that I am attempting

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.