Commits

emmi...@a5195066-8e3e-0410-a82a-05b01b1b9875  committed f896e8c

Use correct docroot in included templates. Thanks to Tobias Loefgren.

  • Participants
  • Parent commits 0807df4

Comments (0)

Files changed (9)

File examples/docroot/extends_path

+{% extends "path1/base1" %}
+{% block title %}replacing the base title{% endblock %}
+{% block content %}replacing the base content - variable: {{ test_var }} after variable {% endblock %}

File examples/docroot/include_path

+main file
+
+{% include "path1/template1" %}
+
+{{ base_var }}

File examples/docroot/include_template

+Including another template: {% include "base" %}
+
+test variable: {{ test_var }}

File examples/docroot/path1/base1

+{% extends "../path2/base2" %}
+
+{% block title2 %}block title 2 from  base1 {% endblock %}
+
+
+

File examples/docroot/path1/template1

+This is template 1.
+
+{{ test_var }}
+
+{% include "../path2/template2" %}

File examples/docroot/path2/base2

+{{ base_var }}
+
+base2 template
+
+{% block title %}block title in base2, should be hidden by main template{% endblock %}
+{% block title2 %}block title2 in base2, should be hidden by base1{% endblock %}
+
+more of base2 template
+
+{% block content %}block content in base 2, should be overwritten{% endblock %}
+
+{% block content2 %}block content2 in base 2, should pass through{% endblock %}
+
+end of base2 template

File examples/docroot/path2/template2

+
+This is template 2

File src/erlydtl/erlydtl_compiler.erl

                     with_dependency({File, CheckSum}, body_ast(ParentParseTree, Context#dtl_context{
                         block_dict = dict:merge(fun(_Key, _ParentVal, ChildVal) -> ChildVal end,
                             BlockDict, Context#dtl_context.block_dict),
-                                parse_trail = [File | Context#dtl_context.parse_trail]}, TreeWalker));
+                                parse_trail = [File | Context#dtl_context.parse_trail], 
+                                doc_root = filename:dirname(File)}, TreeWalker));
                 Err ->
                     throw(Err)
             end        
     case parse(FilePath, Context) of
         {ok, InclusionParseTree, CheckSum} ->
             with_dependency({FilePath, CheckSum}, body_ast(InclusionParseTree, Context#dtl_context{
-                parse_trail = [FilePath | Context#dtl_context.parse_trail]}, TreeWalker));
+                parse_trail = [FilePath | Context#dtl_context.parse_trail], 
+                doc_root = filename:dirname(FilePath) }, TreeWalker));
         Err ->
             throw(Err)
     end.

File src/tests/erlydtl_functional_tests.erl

         "for_records_preset", "include", "if", "if_preset", "ifequal",
         "ifequal_preset", "ifnotequal", "ifnotequal_preset", "now",
         "var", "var_preset", "var_error", "cycle", "custom_tag",
-        "custom_tag_error", "custom_call"].
+        "custom_tag_error", "custom_call", 
+        "include_template", "include_path", "extends_path" ].
 
 setup_compile("for_list_preset") ->
     CompileVars = [{fruit_list, [["apple", "apples"], ["banana", "bananas"], ["coconut", "coconuts"]]}],
     RenderVars = [{test, [integer_to_list(X) || X <- lists:seq(1, 20)]},
                   {a, "Apple"}, {b, "Banana"}, {c, "Cherry"}],
     {ok, RenderVars};
+setup("include_template") ->
+    RenderVars = [{base_var, "base-barstring"}, {test_var, "test-barstring"}],
+    {ok, RenderVars};
+setup("include_path") ->
+    RenderVars = [{base_var, "base-barstring"}, {test_var, "test-barstring"}],
+    {ok, RenderVars};
+setup("extends_path") ->
+    RenderVars = [{base_var, "base-barstring"}, {test_var, "test-barstring"}],
+    {ok, RenderVars};
+
 %%--------------------------------------------------------------------       
 %% Custom tags
 %%--------------------------------------------------------------------