Skip to main content

b:attr

New #1

The tag <b:attr> or attribute is an instruction tag for adding an attribute to the parent element.

<b:attr> Syntax and Attribute

BLOGGER XML LANGUAGE

<div>
<b:attr cond='CONDITION'
        name='ATTRIBUTE_NAME'  <!-- expr:name='EXPRESSION' -->
        value='VALUE'/>        <!-- expr:value='EXPRESSION' -->
</div>
  • <b:attr> tags can also be used with prefix expression expr: in the name and value.
  • Overwrite existing attribute. 
  • Can be used multiple time, in the same parent element.
  • If parent tag is singleton or self closing, tag must be replaced by <b:tag>

<b:attr> Example

GIVE ID AND CLASS

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

The new id attribute with the falue foo  will be added to the tag  <div> and attribute class with the value bar as well as the parent in the HTML rendering.

RESULT

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

ADD AN ATTRIBUTE WITH A CONDITION

<div>
  <b:attr cond='data:view.isPost' name='style' value='background: red'/>
</div>

If the current view of page is Post,  new attribute style with background: red as value, will be injected to the parent tag <div> in HTML rendering.

RENDERED

<div style='background: transparent'>
 
</div>

INJECT  MULTIPLE ATTRIBUTES

<a>
  <b:attr name='href' expr:value='data:label.url'/>
  <b:attr name='target' value='_blank'/>
  <span>TITLE</span>
</a>
The b:attr tag, or the attribute tag, is a tag for simplifying adding an attribute to the parent element, especially conditionally.

Attributes

name - Name of the attribute.
value - Value of the attribute.
cond - Boolean expression for whether to append the attribute

Example usage

 
<div>
<b:attr name='data-foo'
value='data:blog.blogId'
cond='data:view.isHomepage' />

</div>

On homepages, this would produce
 
<div data-foo='123456789012'>
</div>

On other pages, this would produce
 
<div>
</div>

Other Tag

0

Reviews

Give your rating
Back to top Back to bottom