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

  • Home
  • SEARCH
  • 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 8569681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:23:36+00:00 2026-06-11T18:23:36+00:00

I was trying to render a mustache template which is referencing itself in it.

  • 0

I was trying to render a mustache template which is referencing itself in it. But it gives a ‘Stack level too deep’ error.

Here is my code in ruby.

The following snippet of code is in person.rb file

require 'mustache'
require 'active_support'

str = File.read("person.json")
j = ActiveSupport::JSON.decode(str)
Mustache.template_file = "person.mustache"
puts Mustache.render(j)

The following json content is in person.json

{
    "name":"Jason",
    "rels":[
        {"type":"friend",
        "ref":{
            "name":"John",
            "rels":[
                {"type":"friend",
                "ref":{"name":"Chrissy"}}
            ]
        }},
        {"type":"family",
        "ref":{"name":"Owen"}}
    ]
}

The following content is in the file person.mustache file

{{#rels}}
<ul>
  <li>Type: {{type}}</li>
  {{#ref}} {{> person}} {{/ref}}
</ul>
{{/rels}}

can someone point me in the right direction?

  • 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-11T18:23:37+00:00Added an answer on June 11, 2026 at 6:23 pm

    From the fine manual:

    Partials
    […]
    They also inherit the calling context. Whereas in ERB you may have this:

    <%= partial :next_more, :start => start, :size => size %>
    

    Mustache requires only this:

    {{> next_more}}
    

    Why? Because the next_more.mustache file will inherit the size and start methods from the calling context.

    So, if there is no rels in the current context:

        "ref": { "name": "Chrissy" }
    

    then you’ll inherit the rels from the parent. That gives you a partial referencing rels from the parent which activates the partial again which references rels from the parent which keeps going until you run out of stack.

    If you’re going to build a recursive template like this:

    {{#rels}}
    <ul>
      <li>Type: {{type}}</li>
      {{#ref}} {{> person}} {{/ref}}
    </ul>
    {{/rels}}
    

    then you need to have complete objects at each level:

    {
        "name":"Jason",
        "rels":[
            {"type":"friend",
            "ref":{
                "name":"John",
                "rels":[
                    {"type":"friend",
                    "ref":{"name":"Chrissy","rels":[]}} // <--- rels here
                ]
            }},
            {"type":"family",
            "ref":{"name":"Owen","rels":[]}} // <-------------- and here
        ]
    }
    

    You can flesh out your data in the JSON or after you parse it, I’d recommend that you flesh it out after parsing it.

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

Sidebar

Related Questions

So i'm trying to render a template with trimpath in IE8, but when passing
i´m trying to render PDF with renderpdf grails plugin, but their documentation is very
Im trying to render a django template from a database outside of djangos normal
I am trying to render the dictionary content using Django template like this for
Trying to render a list, each of which has an ajax form to get
When trying to render a Django template file in Google App Engine from google.appengine.ext.webapp
I have a simple JSON object graph I'm trying to render using a Mustache
I'm trying to use mustache templates to render very simple forms, however, one of
I'm trying render data in my Jqgrid, but it is just not showing up.
I'm trying to render an action which is in a sub-namespaced controller from within

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.