Not sure the title conveys what I'm meaning to ask, but in the PHP/Rails
world, if you want to omit an attribute in an HTML tag, you're usually going
to wrap it in an if statement:

<body <?php if isset($someVar)?> class="<?= $someVar ?>"<?php endif
?>></body>

Essentially, if $someVar has been set, then you render a class attribute for
the body in the DOM.

I've set up the template components to allow for a class and id string to be
passed into the template body tag using a custom parameter in the page tml:

<t:pagelayout.mainlayout title="Settings" bodyClass="beckon-ui-app"
                        
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd";>

In the associated pagelayout java file, I have this:


    /**
     * The page title, for the <title> element and the 
 element.
     */
    @Property
    @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
    private String title;

    /**
     * The optional classes for the body.
     */
    @Property
    @Parameter(required = false, defaultPrefix = BindingConstants.LITERAL)
    private String bodyClass;

    /**
     * The optional ID for the body.
     */
    @Property
    @Parameter(required = false, defaultPrefix = BindingConstants.LITERAL)
    private String bodyid;


In the layout template tml, I have this:

<body id="${bodyid}" class="${bodyClass}"></body>

What I'm seeing on runtime is that if there is no ID set, the id attribute
on the html body tag isn't rendered. Likewise, for the class attribute. Is
this the expected behavior? Something along the lines that if an attribute
that is being rendered by a variable that is null/doesn't exist is removed
from the DOM?

Thanks!



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Attribute-rendering-in-tags-with-variables-tp5156263p5156263.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to