nested exception is org.thymeleaf.exceptions.TemplateInputException in using LayoutDialect

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

nested exception is org.thymeleaf.exceptions.TemplateInputException in using LayoutDialect

Dave Alex
Hi!
    Iam getting following error:

HTTP Status 500 - Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "layout.html", template might not exist or might not be accessible by any of the configured Template Resolvers (content1:4)


Following is servlet-context.xml

<beans:bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
                <beans:property name="prefix" value="/WEB-INF/templates/" />
                <beans:property name="suffix" value=".html" />
                <beans:property name="characterEncoding" value="UTF-8" />
                <beans:property name="templateMode" value="HTML5" />
                <beans:property name="cacheable" value="false" />               
        </beans:bean>       
       
        <beans:bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
                <beans:property name="templateResolver" ref="templateResolver" />
                <beans:property name="additionalDialects"> 
                      <beans:set> 
                        <beans:bean class="nz.net.ultraq.web.thymeleaf.LayoutDialect"/>
                      </beans:set> 
    </beans:property>
               
        </beans:bean>
       
       
        <beans:bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver"> 
          <beans:property name="templateEngine" ref="templateEngine" /> 
               
        </beans:bean> 


/****************************************************************/

Following is layout.html file in "WEB-INF/templates"  folder



<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
  <head>
    <title>Layout page</title>
    <script src="common-script.js"></script>  </head>
  <body>
    <header>
     

My website

   </header>
   <section layout:fragment="content">
     <p>Page content goes here</p>
   </section>
   <footer>
     <p>My footer</p>
     <p layout:fragment="custom-footer">Custom footer here</p>
   </footer> 
  </body>
</html>

/******************************************************************/

Here is content1.html file in "WEB-INF/templates"

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
  layout:decorator="@{layout.html}">
  <head>
    <title>Content page 1</title>
    <script src="content-script.js"></script>  </head>
  <body>
    <section layout:fragment="content">
      <p>This is a paragraph from content page 1</p>
    </section>
    <footer>
      <p layout:fragment="custom-footer">This is some footer content from content page 1</p>
    </footer>
  </body>
</html>


/**********************************************************************/

When I run application, I get above mentioned error. If I get "layout.html" only, web browser shows the output, but if I try to get content1.html file, I get error.


Can someone guide me what Iam doing wrong and how it can be rectified.

Thanks in advance



 
Reply | Threaded
Open this post in threaded view
|

Re: nested exception is org.thymeleaf.exceptions.TemplateInputException in using LayoutDialect

danielfernandez
Administrator
Hi,

Emanuel will probably be able to answer to your question better than me, but I think that, given the fact you are adding a suffix to your templates at the templater resolver, your:

    layout:decorator="@{layout.html}"

...should in fact be:

    layout:decorator="layout"


Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|

Re: nested exception is org.thymeleaf.exceptions.TemplateInputException in using LayoutDialect

Emanuel
Administrator
In reply to this post by Dave Alex
The 'error resolving template' exception comes from Thymeleaf when it can't find the template file you're asking for (Layout Dialect uses Thymeleaf's template resolvers to locate the file).  Looking at the configuration of your template resolver, you have a prefix of /WEB-INF/templates/ and a suffix of .html which means that Thymeleaf will append those parts before and after the name of the template you specified.

The template you specified is @{layout.html} which will expand and add the prefix/suffix to become: /WEB-INF/templates/layout.html.html

That last bit is probably what's causing the error as you don't have a layout.html.html file.  So try changing the template to just layout  Also, you probably don't need the @{ } notation either.

[EDIT]: Ah, Daniel beat me to it :)
Reply | Threaded
Open this post in threaded view
|

Re: nested exception is org.thymeleaf.exceptions.TemplateInputException in using LayoutDialect

Dave Alex
In reply to this post by Dave Alex
@dfernandez  , @Emanuel  

Just pin piont solution. A really head shot to the problem.

Thanks