How to use Google Blogger Lambda Operators

前端 未结 1 1658
栀梦
栀梦 2021-02-06 16:43

Google Blogger has implemented a new set of Lambda expression operators for its template language. See: https://blogger.googleblog.com/2016/05/more-custom-template-flexibility.h

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-06 17:19

    The solution to my problem

    Stupid of me, if I expect to be able to use a loop I need to specify a loop:

                        
      

    Post found:

    How to use Blogger Lambda Operators

    For those coming here trying to find help I recommend the following article which explains how to use Lambda expressions quite comprehensively: http://www.bloggerever.com/2016/05/what-are-exactly-bloggers-lambda.html and is based on https://productforums.google.com/forum/#!topic/blogger/l3phi8bscGY.

    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:

      
          ...Code here...
    
    

    all would return true if it had both labela and labelb associated with it:

      
          ...Code here...
    
    

    none would return true if it had neither labela and labelb associated with it:

      
          ...Code here...
    
    

    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

      
          ...Code here...
    
    

    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!)

                        
        

    Post found:

    first like filter, but will return the first match only.

                        
        

    Post found:

    map returns an array set containing each result from the Lambda. The code below would display labels in a h1 tag with >> prepended.

    
         

    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.

    0 讨论(0)
提交回复
热议问题