Use of view function in beego template function

The function of the view function: handle the simple business logic   in the view
  1. Create the background function
2. Define the function name in the view
  3. Associate before beego.Run

 

func main () { 
    beego.AddFuncMap ("prepage", ShowPrePage) 
    beego.AddFuncMap ("nextpage", ShowNextPage) 
    beego.Run () 
} 

// Define a function in the background 
func ShowPrePage (pageIndex int) int { 
    if pageIndex == 1 { 
    return pageIndex 
} 
    return pageIndex -1 
} 

func ShowNextPage (pageIndex int, pageCount int) int { 
    if pageIndex == pageCount { 
    return pageIndex 
} 
    return pageIndex + 1 
} 


// HTML code uses 
{{.pageIndex | prepage}} function name: prepage passes one parameter pageIndex 

{{nextpage .pageIndex .pageCount}} Function name: nextpage passes two parameters pageIndex pageCount

  

 

Guess you like

Origin www.cnblogs.com/zhaopp/p/12728735.html