Hugo 等同于 PHP 的 strpos() 函数
来源:stackoverflow
时间:2024-03-08 18:03:25 134浏览 收藏
本篇文章给大家分享《Hugo 等同于 PHP 的 strpos() 函数》,覆盖了Golang的常见基础知识,其实一个语言的全部知识点一篇文章是不可能说完的,但希望通过这些问题,让读者对自己的掌握程度有一定的认识(B 数),从而弥补自己的不足,更好的掌握它。
所以,我想打破 .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()
。
我在使用前文时看到的问题是,虽然它是 markdown 渲染的,但它不能跨越多行。我知道我可以使用 \n
来换行,但这会抵消 markdown 的好处。
谢谢。
解决方案
听起来你可能可以这样做:
{{ 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>
本篇关于《Hugo 等同于 PHP 的 strpos() 函数》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!
-
502 收藏
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
139 收藏
-
204 收藏
-
325 收藏
-
478 收藏
-
486 收藏
-
439 收藏
-
357 收藏
-
352 收藏
-
101 收藏
-
440 收藏
-
212 收藏
-
143 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 514次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 499次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习