Can I pull body attributes (rather than children) up into my sitemesh/freemarker decorator?

StackOverflow https://stackoverflow.com/questions/13061236

  •  14-07-2021
  •  | 
  •  

Question

We're using pages with the following sort of example content:

<html>
    <head>
        <title>Page Title</title>
        <!-- (page-specific JS and styles) -->
    </head>
    <body>
        <h1>Page Title</h1>
        <!-- (rest of page content) -->
    </body>
</html>

And then with SiteMesh + Freemarker we decorate them in something like this:

<!doctype html>
<html>
    <head>
        <title><#if title?? && title?has_content>${title}</#if></title>
        <!-- (global styles and scripts)-->
        ${head}
    </head>
    <body>
        <!-- (Header elements) -->
        ${body}
        <!-- (Footer elements) -->
    </body>
</html>

What I'm wondering is if there's a nice way to propagate any extra attributes on the page-level <body> element to the decorator's <body> element, so they're not simply thrown away?

Was it helpful?

Solution

OK, I eventually found the answer myself after some experimentation :D The body attributes go into page.properties["body.attrName"], which you can use in my case like so:

<#if page.properties["body.class"]??>
    <body class="${page.properties["body.class"]}">
<#else>
    <body>
</#if>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top