digideskio / zotonic

Automatically exported from code.google.com/p/zotonic
0 stars 0 forks source link

z_template:render/3 doing it wrong on rendering template with included template w/ erlydtl tags #126

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Unpack the arhive attached. It contains needed files several templates, 
dispatch rule and resource.
2. Merge with files with any project
3. go to http://localhost:8000/test
4. click on the link

What is the expected output? 
Some render actions after ajax should be appear on screen according to 
templates.

What do you see instead?
HTTP 500 received over AJAX update and some data in logs:

=INFO REPORT==== 18-Nov-2010::17:47:04 ===
DEBUG: resource_stars_test:11  [<<"<html>\n\n<head>\n">>,
                                [[[[],
                                   <<"<script src=\"/lib/js/apps/jquery-1.4.2.min~jquery-ui-1.8.2.min~63457308543.js\" type=\"text/javascript\"></script>">>],
                                  <<"\n">>]],
                                <<"\n">>,
                                [[],
                                 <<"<script src=\"/lib/js/apps/zotonic-1.0~z.widgetmanager~/js/modules/livevalidation-1.3~z.inputoverlay~jquery.loadmask~z.dialog~z.blockminifier~63457308543.js\" type=\"text/javascript\"></script>">>],
                                <<"\n</head>\n\n<body>\n\n<a id=\"">>,
                                "wmyzseph-a",
                                <<"\" href=\"/postback\">Click</a>\n">>,
                                {context,undefined,undefined,undefined,
                                 undefined,undefined,default,undefined,
                                 undefined,undefined,undefined,undefined,
                                 undefined,undefined,undefined,undefined,
                                 undefined,undefined,en,undefined,undefined,
                                 [],
                                 [{"wmyzseph-a","wmyzseph-a",
                                   {event,
                                    [{delegate,resource_stars_test},
                                     {type,click},
                                     {postback,
                                      {render,[{to,"wmyzseph-div"}]}}]}}],
                                 [],[],[],[],[],undefined},
                                <<"\n\n<div id=\"">>,"wmyzseph-div",
                                <<"\">\n">>,
                                [<<"\n">>],
                                <<"\n</div>\n\n">>,
                                {script,[]},
                                <<"\n</body>\n\n</html>\n">>]

=ERROR REPORT==== 18-Nov-2010::17:47:04 ===
webmachine error: path="/postback"
{error,
    {error,function_clause,
        [{z_utils,js_escape,
             [{context,undefined,undefined,undefined,undefined,undefined,
                  default,undefined,undefined,undefined,undefined,undefined,
                  undefined,undefined,undefined,undefined,undefined,undefined,
                  en,undefined,undefined,[],
                  [{"wmyzseph-a","wmyzseph-a",
                    {event,
                        [{delegate,resource_stars_test},
                         {type,click},
                         {postback,{render,[{to,"wmyzseph-div"}]}}]}}],
                  [],[],[],[],[],undefined},
              []]},
         {z_utils,js_escape,2},
         {z_render,update_js,4},
         {action_base_update,render_static,5},
         {z_render,render_actions,4},
         {z_script,'-get_script1/1-fun-1-',2},
         {lists,foldl,3},
         {z_script,get_script1,1}]}}

What version of the product are you using? On what operating system?
version: zotonic today HG snapshot. 

Looks like z_template:render/3 ignores erlydtl-tags in included templates. If I 
remove {% wire %} from test/test_inc.tpl all will be ok.

Original issue reported on code.google.com by hellla...@gmail.com on 18 Nov 2010 at 3:02

Attachments:

GoogleCodeExporter commented 8 years ago
In your event, try to use render_to_iolist/2 instead of render/2.
This will return an iolist with your html and a context with all scripts etc 
collected in it.

event({postback, {render, [{to, To}]}, _TriggerId, _TargetId}, Context) ->
    {Html,ContextHtml} = z_template:render_to_iolist("test/test_head.tpl", [], Context),
    ?DEBUG(Html),
    z_render:wire([{insert_bottom, [{target, To}, {text, Html}]}], ContextHtml).

Original comment by ma...@pobox.com on 18 Nov 2010 at 3:11

GoogleCodeExporter commented 8 years ago
I've replaced render/3 with render_to_iolist/3.
On click now this error:

=ERROR REPORT==== 18-Nov-2010::18:17:57 ===
webmachine error: path="/postback"
{error,
    {error,function_clause,
        [{z_render,render,
             [{script,[]},
              {context,
                  {wm_reqdata,#Port<0.9087>,
                      {dict,4,16,16,8,80,48,
                          {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
                          {{[],[],[],[],
                            [[zotonic_host|stars]],
                            [[resource_module|resource_postback],
                             ['content-type',97,112,112,108,105,99,97,116,105,
                              111,110,47,120,45,106,97,118,97,115,99,114,105,
                              112,116]],
                            [],
                            [['content-encoding',105,100,101,110,116,105,116,
                              121]],
                            [],[],[],[],[],[],[],[]}}},
                      undefined,"127.0.0.1",standard,
                      {wm_log_data,1001290093477154696,undefined,
                          {1290,93477,154749},
                          'POST',
                          {14,
                           {"host",
                            {'Host',"stars.local:8000"},
                            {"accept",
                             {'Accept',"text/plain, */*"},
                             nil,
                             {"accept-language",
                              {'Accept-Language',
                                  "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3"},
                              {"accept-encoding",
                               {'Accept-Encoding',"gzip,deflate"},
                               {"accept-charset",
                                {'Accept-Charset',"UTF-8,*"},
                                nil,nil},
                               nil},
                              {"connection",
                               {'Connection',"keep-alive"},
                               {"cache-control",
                                {'Cache-Control',"no-cache"},
                                nil,nil},
                               {"content-type",
                                {'Content-Type',
                                    "application/x-www-form-urlencoded; charset=UTF-8"},
                                {"content-length",
                                 {'Content-Length',"245"},
                                 nil,nil},
                                {"cookie",
                                 {'Cookie',
                                     "z_pid=rY6uZY9RXDeuLz1hitN6; z_sid=NvjHrex90HMSsfrJjBHX; z_logon=g2gDaAJiAAABdGgCaANiAAAH2mEMYQJoA2EQYTZhDGsAFFBISVRIQldrbXJ5Q3BJVDlyMkE1bQAAABRQSe3XiISX6%2Fju74vp%2Fu3EgtjPrg%3D%3D"},
                                 nil,nil}}}}},
                            {"user-agent",
                             {'User-Agent',
                                 "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101027 Firefox/3.6.12"},
                             {"keep-alive",
                              {'Keep-Alive',"115"},
                              nil,
                              {"pragma",{'Pragma',"no-cache"},nil,nil}},
                             {"x-requested-with",
                              {"X-Requested-With","XMLHttpRequest"},
                              nil,nil}}}},
                          "127.0.0.1","/postback",
                          {1,1},
                          404,0,undefined,undefined},
                      'POST',
                      {1,1},
                      [],"/postback","/postback",
                      {dict,2,16,16,8,80,48,
                          {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
                          {{[],[],[],[],
                            [[zotonic_host|stars]],
                            [],[],[],
                            [[zotonic_dispatch|postback]],
                            [],[],[],[],[],[],[]}}},
                      [],".",500,1073741824,
                      [{"z_pid","rY6uZY9RXDeuLz1hitN6"},
                       {"z_sid","NvjHrex90HMSsfrJjBHX"},
                       {"z_logon",
                        "g2gDaAJiAAABdGgCaANiAAAH2mEMYQJoA2EQYTZhDGsAFFBISVRIQldrbXJ5Q3BJVDlyMkE1bQAAABRQSe3XiISX6%2Fju74vp%2Fu3EgtjPrg%3D%3D"}],
                      [],
                      [{"accept","text/plain, */*"},
                       {"accept-charset","UTF-8,*"},
                       {"accept-encoding","gzip,deflate"},
                       {"accept-language",
                        "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3"},
                       {"cache-control","no-cache"},
                       {"connection","keep-alive"},
                       {"content-length","245"},
                       {"content-type",
                        "application/x-www-form-urlencoded; charset=UTF-8"},
                       {"cookie",
                        "z_pid=rY6uZY9RXDeuLz1hitN6; z_sid=NvjHrex90HMSsfrJjBHX; z_logon=g2gDaAJiAAABdGgCaANiAAAH2mEMYQJoA2EQYTZhDGsAFFBISVRIQldrbXJ5Q3BJVDlyMkE1bQAAABRQSe3XiISX6%2Fju74vp%2Fu3EgtjPrg%3D%3D"},
                       {"host","stars.local:8000"},
                       {"keep-alive","115"},
                       {"pragma","no-cache"},
                       {"user-agent",
                        "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101027 Firefox/3.6.12"},
                       {"x-requested-with","XMLHttpRequest"}],
                      <<"postback=CWWBKDqKK0QzSwTB%2FM6ztkYg%2FGGDaAVkAAVjbGlja2sACmdwcmJ5bnBvLWFrAApncHJieW5wby1haAJkAAZyZW5kZXJsAAAAAWgCZAACdG9rAAxncHJieW5wby1kaXZqZAATcmVzb3VyY2Vfc3RhcnNfdGVzdA%3D%3D&z_trigger_id=gprbynpo-a&z_pageid=wFzjAzy3oYkjFjnMZobk&triggervalue=">>,
                      false,
                      {4,
                       {"cache-control",
                        {"Cache-Control",
                         "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"},
                        nil,
                        {"expires",
                         {"Expires","Wed, 10 Dec 2008 12:30:00 GMT"},
                         {"content-type",
                          {"Content-Type","application/x-javascript"},
                          nil,nil},
                         {"p3p",
                          {"P3P",
                           "CP=\"NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM\""},
                          nil,nil}}}},
                      <<>>,[],none,
                      [{encodings_provided,
                           [{"identity",
                             #Fun<webmachine_resource.0.106118119>}]},
                       {charsets_provided,no_charset},
                       {content_types_provided,
                           [{"application/x-javascript",false}]}]},
                  resource_stars_test,<0.5065.0>,<0.5430.0>,
                  "wFzjAzy3oYkjFjnMZobk",stars,'z_depcache$stars',
                  'z_notifier$stars','z_session_manager$stars',
                  'z_dispatcher$stars','z_template$stars','z_scomp$stars',
                  'z_dropbox$stars','z_pivot_rsc$stars',
                  'z_module_indexer$stars',81962,undefined,en,undefined,
                  undefined,[],
                  [{"fqcfgohn-a","fqcfgohn-a",
                    {event,
                        [{delegate,resource_stars_test},
                         {type,click},
                         {postback,{render,[{to,"fqcfgohn-div"}]}}]}}],
                  [],[],[],[],
                  [[[[[[[[[[[[[[],[<<"<html>\n\n<head>\n">>]],
                              [<<"<script src=\"/lib/js/apps/jquery-1.4.2.min~jquery-ui-1.8.2.min~63457308543.js\" type=\"text/javascript\"></script>">>]],
                             [<<"\n">>]],
                            [<<"\n">>]],
                           [<<"<script src=\"/lib/js/apps/zotonic-1.0~z.widgetmanager~/js/modules/livevalidation-1.3~z.inputoverlay~jquery.loadmask~z.dialog~z.blockminifier~63457308543.js\" type=\"text/javascript\"></script>">>]],
                          [<<"\n</head>\n\n<body>\n\n<a id=\"">>]],
                         "fqcfgohn-a"],
                        [<<"\" href=\"/postback\">Click</a>\n">>]],
                       [<<"\n\n<div id=\"">>]],
                      "fqcfgohn-div"],
                     [<<"\">\n">>]],
                    [<<"\n">>]],
                   [<<"\n</div>\n\n">>]],
                  [{q,[{"zotonic_host","stars"},
                       {"zotonic_dispatch","postback"},
                       {"postback",
                        "CWWBKDqKK0QzSwTB/M6ztkYg/GGDaAVkAAVjbGlja2sACmdwcmJ5bnBvLWFrAApncHJieW5wby1haAJkAAZyZW5kZXJsAAAAAWgCZAACdG9rAAxncHJieW5wby1kaXZqZAATcmVzb3VyY2Vfc3RhcnNfdGVzdA=="},
                       {"z_trigger_id","gprbynpo-a"},
                       {"z_pageid","wFzjAzy3oYkjFjnMZobk"},
                       {"triggervalue",[]}]},
                   {zotonic_dispatch,postback}]}]},
         {z_render,render,2},
         {z_render,render_to_iolist,2},
         {resource_stars_test,event,2},
         {resource_postback,process_post,2},
         {webmachine_resource,resource_call,3},
         {webmachine_resource,do,3},
         {webmachine_decision_core,decision,3}]}}

Original comment by hellla...@gmail.com on 18 Nov 2010 at 3:22

GoogleCodeExporter commented 8 years ago
Looks like there due to {% script %} tag. Anyway, Issue may be closed.

Original comment by hellla...@gmail.com on 18 Nov 2010 at 3:43

GoogleCodeExporter commented 8 years ago
In this kind of "postback" templates you don't need a {% script %} tag.

All scripts collected in the context will be appended to the template being 
returned, so there is a kind of implicit {% script %} tag.

Original comment by ma...@pobox.com on 18 Nov 2010 at 3:48

GoogleCodeExporter commented 8 years ago
In this kind of "postback" templates you don't need a {% script %} tag.

All scripts collected in the context will be appended to the template being 
returned, so there is a kind of implicit {% script %} tag.

Original comment by ma...@pobox.com on 18 Nov 2010 at 3:48

GoogleCodeExporter commented 8 years ago

Original comment by ma...@pobox.com on 18 Nov 2010 at 3:48