登录
首页 >  Golang >  Go问答

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

{{ .params.summary }}

过去,在 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 "|^^|" "
" | safehtml}}

这会变成

进入


      
This is the next line, that would be in array[1] or the next indexed substr.

本篇关于《Hugo 等同于 PHP 的 strpos() 函数》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>