如何解析django样式的模板标签 [英] How to parse django style template tags
本文介绍了如何解析django样式的模板标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要的标签样式解析看起来像 {{form | form_name}}
解决方案
REGEX是要走的路。
\ {\ {* form * \ | *(\S +)* \} \}
应该很好地做窍门。有一点解释:
$ b
$ b > \ {
和 \}
将匹配 {
和}
*
将匹配0到无限空间字符(
)。
(\S +)
将匹配1到无限的非空格字符( a,B,3,_ etc
)。
What's the best way to parse django style template tags in PHP? I know there are plenty of templating libraries for PHP, but I literally just need to parse one tag when I retrieve data from my database.
The style of tag I want to parse looks like {{ form | form_name }}
解决方案
REGEX is the way to go.
\{\{ *form *\| *(\S+) *\}\}
should do the trick nicely.
A bit of explaining:
\{
and\}
will each match{
and}
respectively.*
will match for 0 to infinite space characters ().
(\S+)
will match for 1 to infinite non-space characters (a, B, 3, _ etc
).
这篇关于如何解析django样式的模板标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文