Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 液体模板引擎的实现布局标记_Ruby_Liquid - Fatal编程技术网

Ruby 液体模板引擎的实现布局标记

Ruby 液体模板引擎的实现布局标记,ruby,liquid,Ruby,Liquid,我想用liquid template engine为我的博客设置主题,但默认情况下,该引擎只支持一些基本标记,我想编写自定义标记{%layout'layout_name%} 布局文件:dark.liquid <html> ... {% content_for_body %} ... </html> 和输出 <html> ... welcome to my blog! ... </html> ... 欢迎来到我的博客! ... 谢谢 我不认为

我想用liquid template engine为我的博客设置主题,但默认情况下,该引擎只支持一些基本标记,我想编写自定义标记{%layout'layout_name%}

布局文件:dark.liquid

<html>
...
{% content_for_body %}
...
</html>
和输出

<html>
...
welcome to my blog!
...
</html>

...
欢迎来到我的博客!
...

谢谢

我不认为像这样的事情可能除了抓取第一行并提取布局名称,然后再将
blog.liquid的其余部分传入,例如:

post = "{{ layout 'dark' }}\nWelcome to my blog!"

layout_name = post.split("\n").first.match(/\{\{ layout '(.+)' \}\}/)[1]
#=> "dark"
content = post.split("\n")[1..-1].join("\n")
#=> "Welcome to my blog!"

它也应该是“{content}u for_body}”;“{%…%}”用于标记块,如if语句。

我认为这样的事情不可能发生,除了在传递blog.liquid的其余部分之前抓取第一行并提取布局名称,例如:

post = "{{ layout 'dark' }}\nWelcome to my blog!"

layout_name = post.split("\n").first.match(/\{\{ layout '(.+)' \}\}/)[1]
#=> "dark"
content = post.split("\n")[1..-1].join("\n")
#=> "Welcome to my blog!"

它也应该是“{content}u for_body}”;“{%…%}”用于像if语句一样的标记块。

@hawx,我真的不明白你的解决方案。“你能给我进一步解释吗?”哈克斯,我真的不明白你的解决办法。你能给我进一步解释一下吗?