Hugo 相当于 PHP 的 strpos()
Hugo's equivalent of PHP's strpos()
所以,我想拆分 .Content
以适应不同的导航标签。如果有更好的模式可以完成,请告诉我。
所以,在我的 /content/shop/product-name/index.md
前面内容包含:
# summary
summary: "This is the **product's** summary which will render markdown"
---
This is the first line of the full description of the product. This section of the ./index.md
page is referenced in the `single.html` file as `.Content`.|^^|This is the next part of the
.Content that I want to throw into a different nav-tab.
然后在/layouts/shop/single.html
:
<div class="row">
<div class="col-lg-12">
{{ .Params.summary }}
</div>
</div>
<div class="row">
<div class="col-lg-12">
<nav class="product-info-tabs wc-tabs mt-5 mb-5">
<div class="nav nav-tabs nav-fill" id="nav-tab" role="tablist">
<a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab"
aria-controls="nav-home" aria-selected="true">Description</a>
<a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab"
aria-controls="nav-profile" aria-selected="false">Additional Information</a>
<a class="nav-item nav-link" id="nav-contact-tab" data-toggle="tab" href="#nav-contact" role="tab"
aria-controls="nav-contact" aria-selected="false">Reviews</a>
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
{{ .Content }}
</div>
...
在过去的日子里,在 PHP 中,我可以使用 strpos(.Content, '|^^|')
然后 substr(.Content, 0, (strpos(.Content, '|^^|'))
来获取一段文本。您还可以将字符串放入带有用户配置的分隔符 split('|^^|', .Content)
的数组中。
所以,回到 Hugo,在 .Content
之内,我可以有类似的东西:
This is the content. This is the last line before being split.|^^|This is the next line, that would be in array[1] or the next indexed substr.
我正在尝试将 .Content
的这两个部分放入 single.html
页面的不同选项卡中。每个产品 .Content
显然会有所不同,所以我不能真正有一个一致的计数来使用 Hugo 的 substr()
。
我在使用 front matter 时看到的问题是,虽然它是 markdown 呈现的,但它不能跨越多行。我知道我可以使用 \n
换行,但这会破坏降价的好处。
谢谢。
听起来你可能会这样做:
{{ replace .Content "|^^|" "</div><div class='tab-pane fade show'>" | safeHTML}}
哪个会转
<div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
This is the content. This is the last line before being split.|^^|This is the next line, that would be in array[1] or the next indexed substr.
</div>
进入
<div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
This is the content. This is the last line before being split.
</div>
<div class='tab-pane fade show'>
This is the next line, that would be in array[1] or the next indexed substr.
</div>
所以,我想拆分 .Content
以适应不同的导航标签。如果有更好的模式可以完成,请告诉我。
所以,在我的 /content/shop/product-name/index.md
前面内容包含:
# summary
summary: "This is the **product's** summary which will render markdown"
---
This is the first line of the full description of the product. This section of the ./index.md
page is referenced in the `single.html` file as `.Content`.|^^|This is the next part of the
.Content that I want to throw into a different nav-tab.
然后在/layouts/shop/single.html
:
<div class="row">
<div class="col-lg-12">
{{ .Params.summary }}
</div>
</div>
<div class="row">
<div class="col-lg-12">
<nav class="product-info-tabs wc-tabs mt-5 mb-5">
<div class="nav nav-tabs nav-fill" id="nav-tab" role="tablist">
<a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab"
aria-controls="nav-home" aria-selected="true">Description</a>
<a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab"
aria-controls="nav-profile" aria-selected="false">Additional Information</a>
<a class="nav-item nav-link" id="nav-contact-tab" data-toggle="tab" href="#nav-contact" role="tab"
aria-controls="nav-contact" aria-selected="false">Reviews</a>
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
{{ .Content }}
</div>
...
在过去的日子里,在 PHP 中,我可以使用 strpos(.Content, '|^^|')
然后 substr(.Content, 0, (strpos(.Content, '|^^|'))
来获取一段文本。您还可以将字符串放入带有用户配置的分隔符 split('|^^|', .Content)
的数组中。
所以,回到 Hugo,在 .Content
之内,我可以有类似的东西:
This is the content. This is the last line before being split.|^^|This is the next line, that would be in array[1] or the next indexed substr.
我正在尝试将 .Content
的这两个部分放入 single.html
页面的不同选项卡中。每个产品 .Content
显然会有所不同,所以我不能真正有一个一致的计数来使用 Hugo 的 substr()
。
我在使用 front matter 时看到的问题是,虽然它是 markdown 呈现的,但它不能跨越多行。我知道我可以使用 \n
换行,但这会破坏降价的好处。
谢谢。
听起来你可能会这样做:
{{ replace .Content "|^^|" "</div><div class='tab-pane fade show'>" | safeHTML}}
哪个会转
<div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
This is the content. This is the last line before being split.|^^|This is the next line, that would be in array[1] or the next indexed substr.
</div>
进入
<div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
This is the content. This is the last line before being split.
</div>
<div class='tab-pane fade show'>
This is the next line, that would be in array[1] or the next indexed substr.
</div>