Latest news, food, business, travel, sport, Tips and Tricks...

Blogger b:attr Tag

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>

Other Tag

 

,

No comments:

Post a Comment