handlebars.js 并隐藏 if 列表
handlebars.js and hide if list
正在努力学习这个handlebars.js,目前我有:
<ul class="productView-thumbnails"{{#gt product.images.length 5}} data-slick='{
"infinite": false,
"mobileFirst": true,
"slidesToShow": 5,
"slidesToScroll": 1
}'{{/gt}}>
{{#each product.images}}
<li class="productView-thumbnail">
<a
class="productView-thumbnail-link"
href="{{getImage this 'product_size' (cdn ../theme_settings.default_image_product)}}"
data-image-gallery-item
data-image-gallery-new-image-url="{{getImage this 'product_size' (cdn ../theme_settings.default_image_product)}}"
data-image-gallery-zoom-image-url="{{getImage this 'zoom_size' (cdn ../theme_settings.default_image_product)}}">
<img class="lazyload" data-sizes="auto" src="{{cdn 'img/loading.svg'}}" data-src="{{getImage this 'productview_thumb_size' (cdn ../theme_settings.default_image_product)}}" alt="{{this.alt}}" title="{{this.alt}}">
</a>
</li>
{{/each}}
</ul>
所以我需要一些 IF 语句的效果,如果只有 1 张图像 (li),然后将 display:none 应用于 class productView-thumbnails
如果只返回一个 LI,我试图隐藏整个 UL。这可能吗?
您应该只需要构造您的车把块。车把控件不是 HTML 元素,因此您可以在 if 语句中包装部分 HTML 结构。
考虑到您已经注册了 gt-helper:
{{#gt product.images.length 1}}
<ul class="productView-thumbnails"{{#gt product.images.length 5}} data-slick='{
…}'{{/gt}}>
{{/gt}}
{{#each product.images}}
{{#gt product.images.length 1}}
<li class="productView-thumbnail">
{{/gt}}
…
{{#gt product.images.length 1}}
</li>
{{/gt}}
{{/each}}
…
{{#gt product.images.length 1}}
</ul>
{{/gt}}
正在努力学习这个handlebars.js,目前我有:
<ul class="productView-thumbnails"{{#gt product.images.length 5}} data-slick='{
"infinite": false,
"mobileFirst": true,
"slidesToShow": 5,
"slidesToScroll": 1
}'{{/gt}}>
{{#each product.images}}
<li class="productView-thumbnail">
<a
class="productView-thumbnail-link"
href="{{getImage this 'product_size' (cdn ../theme_settings.default_image_product)}}"
data-image-gallery-item
data-image-gallery-new-image-url="{{getImage this 'product_size' (cdn ../theme_settings.default_image_product)}}"
data-image-gallery-zoom-image-url="{{getImage this 'zoom_size' (cdn ../theme_settings.default_image_product)}}">
<img class="lazyload" data-sizes="auto" src="{{cdn 'img/loading.svg'}}" data-src="{{getImage this 'productview_thumb_size' (cdn ../theme_settings.default_image_product)}}" alt="{{this.alt}}" title="{{this.alt}}">
</a>
</li>
{{/each}}
</ul>
所以我需要一些 IF 语句的效果,如果只有 1 张图像 (li),然后将 display:none 应用于 class productView-thumbnails
如果只返回一个 LI,我试图隐藏整个 UL。这可能吗?
您应该只需要构造您的车把块。车把控件不是 HTML 元素,因此您可以在 if 语句中包装部分 HTML 结构。
考虑到您已经注册了 gt-helper:
{{#gt product.images.length 1}}
<ul class="productView-thumbnails"{{#gt product.images.length 5}} data-slick='{
…}'{{/gt}}>
{{/gt}}
{{#each product.images}}
{{#gt product.images.length 1}}
<li class="productView-thumbnail">
{{/gt}}
…
{{#gt product.images.length 1}}
</li>
{{/gt}}
{{/each}}
…
{{#gt product.images.length 1}}
</ul>
{{/gt}}