我有此代码:
package main
import (
"fmt"
)
func main() {
combos := []string{"A","B","C","D","E","F"}
combos = GetCombos(combos, 3)
fmt.Println(combos)
}
func GetCombos(set []string, depth int) []string {
var results []string
element := make([]string, depth)
return GetEnvCombos2(set, depth, 0, element, results)
}
func GetCombos2(set []string, depth int, start int, element, results []string) []string {
if depth == 0 {
var guess string
for _, e := range element {
guess += e
}
results = append(results, guess)
return results
}
for i := start; i <= len(set) - depth; i++ {
element[len(element) - depth] = set[i]
results = append(results, GetEnvCombos2(set, depth - 1, i + 1, element, results)...)
}
return nil
}
这给我错误:
{% set foto = 'photo_gallery/' ~ {{ image.id }} ~ '/' %}
{% set thumbs = 'photo_gallery/thumbs/' ~ {{ image.id }} ~ '/' %}
<img src="{{ pageTemplate.pageHeader.mainUrl }}{{ image.image |replace({foto: thumbs}) }}">
如何维修?
答案 0 :(得分:0)
这是与此副本:if variable twig on symfony
在添加问题之前,请记住在论坛上进行深入检查:)
正确的代码是:
{% set foto = 'photo_gallery/' ~ image.id ~ '/' %}
{% set thumbs = 'photo_gallery/thumbs/' ~ image.id ~ '/' %}
<img src="{{ pageTemplate.pageHeader.mainUrl }}{{ image.image |replace({foto: thumbs}) }}">
在树枝中,{%%}表示并执行,这意味着里面的内容会起作用。在这些标记中时,不需要使用{{}},因为只要不加引号,twig就可以解释您的变量名。
此处有更多示例和详细信息:https://twig.symfony.com/doc/2.x/templates.html