Filters are modules that export their methods to liquid. All methods will have to take at least one parameter which represents the input of the filter. The return value will be the output of the filter.
module Jekyll module AssetFilter def asset_url(input) "http://www.example.com/#{input}?#{Time.now.to_i}" end end end Liquid::Template.register_filter(Jekyll::AssetFilter)
ProTip™: Access the site object using Liquid
Jekyll lets you access the
site
object through the@context.registers
feature of Liquid at@context.registers[:site]
. For example, you can access the global configuration file_config.yml
using@context.registers[:site].config
.
© 2020 Jekyll Core Team and contributors
Licensed under the MIT license.
https://jekyllrb.com/docs/plugins/filters/