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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:36:05+00:00 2026-05-28T20:36:05+00:00

I’m using mustache to render stuff on the server, but also on the client.

  • 0

I’m using mustache to render stuff on the server, but also on the client. The strategy is that I have a single page app (rendered with mustache on the server) and this template pulls snippets from the server and uses them to render json on the client too.

Now the problem is with the templates. I want to render the labels on the server, but leave some mustache syntax in place to be rendered on the client. Let’s say I have a template like this:

<html>
<head><title>{{label.title}}</title></head>
<body>
    <h1>{{name}}</h1>
    <p>{{description}}</p>
</body>
</html>

Server side rendering will fill out the label, but now it also removes the placeholders that are not visible on the context.

<html>
<head><title>Ze zjerman title</title></head>
<body>
    <h1></h1>
    <p></p>
</body>
</html>

Is there a way to plug into Scalate and avoid this? I naively tried to get away with:

templateEngine.layout(path, Map(attributes:_*).withDefault((key)=>"{{"+key+"}}"))

… but obviously that will be discarded as soon as the map is processed through a loop (e.g. in TemplateEngine line 576). Where is the proper plug point for this?

I’ve also found the noneString and nullString in RenderContext, but I think I can’t make the renderer output a key there, since these variables are just Strings…

I’m using scalatra-scalate 2.0.2 and scala 2.9.0-1.

  • 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-05-28T20:36:05+00:00Added an answer on May 28, 2026 at 8:36 pm

    You could use an alternate delimiter for the data you know will be populated client side. See: Set Delimeter

    Server side template:

    <h1>{{title}}</h1>
    <p> [[ client.name ]] - [[ client.description ]] </p>
    

    Server side data:

    {title : "Hello"}
    

    Prepend your alternate delimiter to the rendered server template and then render client side.

    var client_template = "{{=[[ ]]=}}" + server_rendered,
    client_data = { client : { name : "Max", description : "world"}},
    client_rendered = Mustache.render(client_template, client_data);
    

    I made a working jsFiddle to show it working. Check out the console.log to see the server template before and after.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.