Skip to main content

b:class

New #1

Like the name, <b:class> is an singleton tag to injecting class attribute to their parent. Almost same as <b:attr> but this one cant overwrite existing parent value.

<b:class>  Syntax and Attribute

BLOGGER XML LANGUAGE

<b:class cond='EXPRESSION'
         name='STRING'/>
 
<b:class cond='EXPRESSION'
         expr:name='EXPRESSION'/>

<b:class> Examples

ADD A CLASS

<p>
  <b:class name='foo'/>
</p>

The new class foo will be added to the parent tag <p> in the HTML rendering.

ADD A CLASS WITH A CONDITION

<div>
  <b:class cond='data:view.isHomepage' name='foo'/>
</div>

The foo class will be added to the parent tag <p> in HTML rendering only if the current page is the homepage.

ADD A CLASS TO AN EXISTING CLASS

<div class='foo'>
  <b:class name='bar'/>
</div>

This example injecting class bar to the parent tag <div> in the HTML rendering. and existing classes in the parent tag are retained.

RESULT

<div class='foo bar'>
 
</div>

INJECTING MULTIPLE CLASSES

<div class='foo'>
  <b:class name='bar'/>
  <b:class name='baz'/>
</div>

The new classes bar and baz will be added to the parent tag <div> in the HTML rendering and Existing classes in the parent tag are untouched.

RESULT

<div class='foo bar baz'>
 
</div>

WITH TERNARY OPERATION

<div>
  <b:class expr:name='data:view.isHomepage ? "foo" : "bar"'/>
</div>

With an expression in ternary operation, like this example, if the current view is Homepage the class foo will be injected to tag <div>, else bar will be chosen.

Other Tag

0

Reviews

Give your rating
Back to top Back to bottom