liqid中有二种标签类型:
普通输出文本或者变量
Hello {{name}}Hello {{user.name}}Hello {{ 'tobi' }} |
filter的使用
管道符|左侧的内容输出,做为右边filter方法的第一个参数输入,这与linux和管道符设计比较相似。
Hello {{ 'tobi' | upcase }}Hello tobi has {{ 'tobi' | size }} letters!Hello {{ '*tobi*' | textilize | upcase }}Hello {{ 'now' | date: "%Y %h" }} |
Standard Filters
date - reformat a date (syntax reference)capitalize - capitalize words in the input sentencedowncase - convert an input string to lowercaseupcase - convert an input string to uppercasefirst - get the first element of the passed in arraylast - get the last element of the passed in arrayjoin - join elements of the array with certain character between themsort - sort elements of the arraymap - map/collect an array on a given propertysize - return the size of an array or stringescape - escape a stringescape_once - returns an escaped version of html without affecting existing escaped entitiesstrip_html - strip html from stringstrip_newlines - strip all newlines (\n) from stringnewline_to_br - replace each newline (\n) with html breakreplace - replace each occurrence e.g. {{ 'foofoo' | replace:'foo','bar' }} #=> 'barbar'replace_first - replace the first occurrence e.g. {{ 'barbar' | replace_first:'bar','foo' }} #=> 'foobar'remove - remove each occurrence e.g. {{ 'foobarfoobar' | remove:'foo' }} #=> 'barbar'remove_first - remove the first occurrence e.g. {{ 'barbar' | remove_first:'bar' }} #=> 'bar'truncate - truncate a string down to x characters. It also accepts a second parameter that will append to the string e.g. {{ 'foobarfoobar' | truncate: 5, '.' }} #=> 'foob.'truncatewords - truncate a string down to x wordsprepend - prepend a string e.g. {{ 'bar' | prepend:'foo' }} #=> 'foobar'append - append a string e.g. {{ 'foo' | append:'bar' }} #=> 'foobar'slice - slice a string. Takes an offset and length, e.g. {{ "hello" | slice: -3, 3 }} #=> llominus - subtraction e.g. {{ 4 | minus:2 }} #=> 2plus - addition e.g. {{ '1' | plus:'1' }} #=> 2, {{ 1 | plus:1 }} #=> 2times - multiplication e.g {{ 5 | times:4 }} #=> 20divided_by - integer division e.g. {{ 10 | divided_by:3 }} #=> 3round - rounds input to the nearest integer or specified number of decimalssplit - split a string on a matching pattern e.g. {{ "a~b" | split:"~" }} #=> ['a','b']modulo - remainder, e.g. {{ 3 | modulo:2 }} #=> 1 |
逻辑控制
assign - Assigns some value to a variablecapture - Block tag that captures text into a variablecase - Block tag, its the standard case...when blockcomment - Block tag, comments out the text in the blockcycle - Cycle is usually used within a loop to alternate between values, like colors or DOM classes.for - For loopbreak - Exits a for loopcontinue Skips the remaining code in the current for loop and continues with the next loopif - Standard if/else blockinclude - Includes another template; useful for partialsraw - temporarily disable tag processing to avoid syntax conflicts.unless - Mirror of if statement |
jekyll filters
{{ site.time | date_to_xmlschema }}{{ site.time | date_to_rfc822 }}{{ site.time | date_to_string }}{{ site.time | date_to_long_string }}{{ site.members | where:"graduation_year","2014" }}{{ site.members | group_by:"graduation_year" }}{{ page.content | xml_escape }}{{ "foo,bar;baz?" | cgi_escape }}{{ "foo, bar \baz?" | uri_escape }}{{ page.content | number_of_words }}{{ page.tags | array_to_sentence_string }}{{ page.excerpt | markdownify }}{{ some_scss | scssify }} {{ some_sass | sassify }}{{ "The _config.yml file" | slugify }}{{ "The _config.yml file" | slugify: 'pretty' }}{{ site.data.projects | jsonify }}{{ page.tags | sort }}{{ site.posts | sort: 'author' }}{{ site.pages | sort: 'title', 'last' }} |
jekyll tags
{% include footer.html %}{% include footer.html param="value" variable-param=page.variable %}{{ include.param }}{% include_relative somedir/footer.html %}{% codeblock lang:ruby %}{% codeblock lang:ruby linenos %} |