1

Forgive me for opening this topic yet again, but I cannot find this solution anywhere, and it is driving me crazy.

I come from a Django-like templating system, where I can extend layouts like so:

child.html

{% extends 'base.html' %}

{% block title %}My Page Title{% endblock %}

{% block content %}
<p>My Page Body</p>
{% endblock content %}

base.html

<html>
<head>
   <title>{% block title %}{% endblock %}</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>

In Tiles, I'd like to do something similar, where I can set the title of the page in a child template. I've tried using <tiles:putAttribute /> in my child templates, but they do not get passed to the parent template.

Does Tiles not handle templates in this bottom-to-top fashion? I've found a bunch of solutions using spring messages or Tiles EL, but these all require setting page titles in my Controller layer. In my opinion, page titles are part of the View layer.

I'm using a dynamic tiles definition to load my templates, so creating a separate tiles definition for each page is out of the question.

Mike
  • 2,334
  • 1
  • 23
  • 27
  • I'm kind of looking for the same type of solution. Have you been able to resolve this, or did you end up working around it? – Eric B. Nov 06 '13 at 16:45
  • I was unable to figure out a solution using tiles. I am looking into using solely Thymeleaf (along with thymeleaf-layout-dialect) as the template engine, as it allows this, as well as many other dynamic features. – Mike Nov 06 '13 at 19:27

1 Answers1

0

the child template must be included before you attempt to use the attribute in the parent template. in this case you can just put the values into the requestScope and not worry about the tiles attribute scope.

otherwise usually in this situation you need to break the composition up a little more.

for example instead of trying to directly write out the attribute in the parent template, you can be inserting another template. this new template has a similar composition to the other child template you already have, and takes responsibility for writing out the attribute, rather than trying to pass this attribute around.

mck
  • 1,152
  • 10
  • 10