Implement layout tag for liquid template engine
I want to themed my blog that use liquid template engine, but default, the engine only support some basic tags, I want to write custom tag {% layout 'layout_name' %}
Layout file: dark.liquid
开发者_如何学运维<html>
...
{% content_for_body %}
...
</html>
And template file: blog.liquid
{% layout 'dark' %}
welcome to my blog!
And output
<html>
...
welcome to my blog!
...
</html>
Thanks!
I don't think that something like this is possibly except for grabbing the first line and extracting the layout name before passing the rest of blog.liquid
in, for example:
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!"
Also it should be "{{ content_for_body }}"; "{% ... %}" is used for tag blocks like an if statement.
精彩评论