rip747 / cfml-liquid

a port of the liquid templating language to coldfusion
MIT License
14 stars 7 forks source link

Stack overflow when template includes itself #11

Open adrianscott83 opened 11 years ago

adrianscott83 commented 11 years ago

For recursively included templates, the LiquidTagInclude will consume all memory due to the parse method's call to tokenize. Possibly perform this action within the render function?

rip747 commented 11 years ago

can you give me an example of the template that will cause the error

adrianscott83 commented 11 years ago

Sure thing. Here is a really basic example for a file named blog_comment.liquid. This would depict a series of blog comment entries that may contain child entries as well. The context being passed to this file would contain the name, body, and an array of child comments, if any.

<div class="comment">
  <div class="comment-name">{{ blog_comment.name }}</div>
  <div class="comment-body">{{ blog_comment.body }}</div>

  {% comment %} Recursively call the comments and output them here, if any {% endcomment %}
  {% if blog_comment.comments %}
    <div class="comment-children">
      {% include 'blog_comment' for blog_comment.comments %}
    </div>
  {% endif %}
</div>
rip747 commented 11 years ago

can you post the code for your blog_comment drop

adrianscott83 commented 11 years ago

The blog.liquid file, which includes the blog_comment.liquid file initially, would look like this:

<div class="blog">
  <h1>{{ title }}</h1>
  <div class="blog-content">{{ content }}</div>
  {% if comments %}
    {% include 'blog_comment' for comments %}
  {% endif %}
</div>

And a context like the following could be provided to the renderer:

<cfset context = {
  'title' = 'My Blog',
  'content' = '<p>Some content goes here.</p>',
  'comments' = [
    {
      'name' = 'Bob',
      'body' = 'Great blog!'
    },
    {
      'name' = 'Frank',
      'body' = 'I really get a lot out of this blog, thanks.',
      'comments' = [
        {
          'name' = 'Adrian',
          'body' = 'No problem, thanks for reading.'
        },
        {
          'name' = 'Frank',
          'body' = 'Any idea when it will be updated again?',
          'comments' = [
            {
              'name' = 'Adrian',
              'body' = 'When I have time, I guess.'
            }
          ]
        }
      ]
    },
    {
      'name' = 'Sally',
      'body' = 'Looking forward to the next one!'
    }
  ]
} />