Search code examples
templatesinheritanceplayframeworkplayframework-1.x

Template inheritance conflict (multiple doLayout in the same page)


I have a small problem with play-framwork (1.2.4). I want to have a tag inherit another tag, and this one be included in a html page extending another web page. The best way to explain is with a schema :

wanted architecture

However, it did not work the way I want. In fact, the extends in the test.tag file seems to overwrite the one in Screen.html. Then, the content of all the Screen.html is included in the block.tag #{doLayout /} instead of in the one of main.html

Is there any way to do what I want ? Thanks.


Here is the sources :

main.html

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <body>
    #{doLayout /}
    </body>
</html>

Screen.html

#{extends 'main.html' /}
<div id="Screen.html">
    #{test  /}
</div>

test.tag

#{extends 'tags/block.tag' /}
test.tag

block.tag

<div id="test">
    #{doLayout /}
</div>

The generated html when the page is called

<div id="test">
    <div id="Screen.html">
        test.tag
    </div>
</div>

As you can see, the main.html is not included and the the Screen is included in the block. Any ideas ?


For information, the wanted output :

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <body>
        <div id="Screen.html">
            <div id="test">
                test.tag
            </div>
        </div>
    </body>
</html>

Solution

  • You can try using #{extends /} in your templates but not use them in tags.

    To have some more flexibility in building tags on top of another, you could do:

    test.tag:

    #{block }
    test.tag
    #{/block}
    

    and block.tag:

    <div id="test">
    #{doBody /}
    </div>
    

    with this you are passing part of the body from a test.tag to a block.tag and inserting it somewhere in block.tag using #{doBody /}