extending templates and using variables

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

extending templates and using variables

is it possible to have something like

<title layout:fragment="title">My Company :: </title>

and then when extending this template

<title layout:fragment="title">Jobs</title>

the result i'm looking for is
<title>My Company :: Jobs</title>
Reply | Threaded
Open this post in threaded view

Re: extending templates and using variables

The layout dialect doesn't do that right now, so you need to specify the full title.  (Oh, and you don't need to specify layout:fragment on the <title> element - the layout dialect automatically overrides the parent template's <title> :) )

I can imagine such a feature would be useful (I've got breadcrumbs in the title on my website by spelling out the website name in every template.  Something like this would save me having to do that).  I've had a quick think about it and have some ideas (not sure if they're good ideas though).

One idea is to specify a setting in the constructor/setter to set that behaviour globally:
// Make templates append to the right of the layout's title:
templateEngine.addDialect(new LayoutDialect(LayoutDialect.EXTEND_TITLE_RIGHT));

// Same thing, but in Spring XML configuration:
<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
  <property name="templateResolver" ref="templateResolver"/>
  <property name="dialects">
      <bean class="org.thymeleaf.spring3.dialect.SpringStandardDialect"/>
      <bean class="nz.net.ultraq.web.thymeleaf.LayoutDialect">
        <property name="extendTitle" value="right"/>

Maybe another way would be to create a new attribute that you set on <title>, making it only apply to certain pages:
<title layout:extend-title="right">Jobs</title>

Or maybe a combination of both to give developers greater control.

What do you think?