• Đăng ký
  • Đăng nhập

Blogger Script

📅 — 👀 1665 — 👦

Trang này có hữu ích không?

👍 Có (15)        👎 Không (19)


The following article will detail the blogger's variables, functions, and language.

Blogger Lambda Operators

<b:loop values='data:posts filter (p  => p.id  != 0)'  var='post'>                    
  <h1>Post found: <data:post.title/></h1>           
</b:loop>

Javascript was never meant to be the first choice to change DOM on load, instead Blogger layout data tags helps us to make the template with native codes, so that the response time gets better and lesser Javascript is used. Previously added expression were indeed useful ones and the new expressions are much more powerful.

Loops are basic concept in Javascript as well as in Blogger. Just like we loop the array and access each item (using <b:loop>tag), we can do the same with Blogger. But lambda expressions let us do processing with array without looping it.
Lambda expressions again works on the basic principle of if and else condition. Point to note that these new expressions work on a set of elements and practically Blogger have 3 sets only we can work on.

  • Comments
  • Labels
  • Posts
In essence there are 7 Lambda operators
  • any
  • all
  • none
  • count
  • filter
  • map
  • first
Each of which can be used either inside an if or loop conditional statement. Some untested sample code follows to help get you started.
The any operator returns true if any items in the Lambda return true, so for example, the following code would return true if a post had a label labela or labelb associated with it:
<b:if cond='data:post.labels any (l  => l.name in {"labela","labelb"})'>
      ...Code here...
</b:if>
all would return true if it had both labela and labelb associated with it:
<b:if cond='data:post.labels all (l  => l.name not in {"labela","labelb"})'>
      ...Code here...
</b:if>
none would return true if it had neither labela and labelb associated with it:
<b:if cond='data:post.labels all (l  => l.name not in {"labela","labelb"})'>
      ...Code here...
</b:if>
count would return 0, 1 or 2 depending on whether a post had neither labela or labelb associated with it, or just labela or both labela and labelb
<b:if cond='data:post.labels count (l  => l.name not in {"labela","labelb"})'>
      ...Code here...
</b:if>
filter will return an array and requires a loop. The example below would print out the title of each post unless it had an id of 0 (which i don't is possible!)
<b:loop values='data:posts filter (p  => p.id  != 0)'  var='post'>                    
    <h1>Post found: <data:post.title/></h1>           
</b:loop>
first like filter, but will return the first match only.
<b:loop values='data:posts first(p  => p.timestamp  == "4.2.09")'  var='post'>                    
    <h1>Post found: <data:post.title/></h1>           
</b:loop>
map returns an array set containing each result from the Lambda. The code below would display labels in a h1 tag with >> prepended.
<b:loop values='data:post.labels map (l=> ">>" + l.name)' var='label'>
     <h1><data:label/></h1>
</b:loop>

A final note: the article linked to suggests the Lambda's may only be applied to post, label and comment elements. It certainly works with the first two but I haven't tried it with comments.

Function Of Blogger :

resizeImage(data:post.firstImageUrl, 435, "2:3") // change size image with param : url, width, ratio

 

View Blogger Variable

Để lại một bình luận


📁 Blogspot