From 7d76d5e48e47514e819c5eca57ef40ebe7047778 Mon Sep 17 00:00:00 2001 From: Sri Pravan Paturi Date: Thu, 8 Nov 2018 04:10:10 +0530 Subject: [PATCH] Add documentation for custom tag blocks (#7359) Merge pull request 7359 --- docs/_docs/plugins/tags.md | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/_docs/plugins/tags.md b/docs/_docs/plugins/tags.md index 3681d623..a5a3af57 100644 --- a/docs/_docs/plugins/tags.md +++ b/docs/_docs/plugins/tags.md @@ -70,3 +70,46 @@ And we would get something like this on the page: ```html

page rendered at: Tue June 22 23:38:47 –0500 2010

``` + +## Tag Blocks + +The `render_time` tag seen above can also be rewritten as a tag block by +inheriting the `Liquid::Block` class. Look at the example below: + +```ruby +module Jekyll + class RenderTimeTagBlock < Liquid::Block + + def render(context) + text = super + "

#{text} #{Time.now}

" + end + + end +end + +Liquid::Template.register_tag('render_time', Jekyll::RenderTimeTagBlock) +``` + +We can now use the tag block anywhere: + +{% raw %} +```liquid +{% render_time %} +page rendered at: +{% endrender_time %} +``` +{% endraw %} + +And we would still get the same output as above on the page: + +```html +

page rendered at: Tue June 22 23:38:47 –0500 2010

+``` + +
+

In the above example, the tag block and the tag are both registered with + the name render_time but to register a tag and a tag block using + the same name in the same project is not recommended as this may lead to + conflicts.

+
\ No newline at end of file