# pageProperty

## Purpose

Used in layouts to output the contents a property of the decorated page. Equivalent to the SiteMesh <decorator:getProperty/> tag.

## Examples

Example decorated page:

    <html>
       <head>
            <meta name="layout" content="myLayout" />
            <script src="myscript.js" />
       </head>
       <body onload="alert('hello');">Page to be decorated</body>
    </html>

Example decorator layout:

    <html>
       <head>
            <script src="global.js" />
            <g:layoutHead />
       </head>
       <body onload="${pageProperty(name:'body.onload')}"><g:layoutBody /></body>
    </html>

Results in:

    <html>
       <head>
            <script src="global.js" />
            <script src="myscript.js" />
       </head>
       <body onload="alert('hello');">Page to be decorated</body>
    </html>

## Source

Show Source

    def pageProperty = { attrs ->
            if (!attrs.name) {
                throwTagError("Tag [pageProperty] is missing required attribute [name]")
            }        def propertyName = attrs.name
            def htmlPage = getPage()
            def propertyValue        if (htmlPage instanceof GSPSitemeshPage) {
                // check if there is an component content buffer
                propertyValue = htmlPage.getContentBuffer(propertyName)
            }        if (!propertyValue) {
                propertyValue = htmlPage.getProperty(propertyName)
            }        if (!propertyValue) {
                propertyValue = attrs.'default'
            }        if (propertyValue) {
                if (attrs.writeEntireProperty) {
                    out << ' '
                    out << propertyName.substring(propertyName.lastIndexOf('.') + 1)
                    out << "=\""
                    out << propertyValue
                    out << "\""
                }
                else {
                    out << propertyValue
                }
            }
        }