---
title: "#118 Liquid"
author: "CaiDeHen"
date: "2008-12-12T16:18:24Z"
tags: []
slug: "118-liquid"
draft: false
lastmod: "2008-12-12T16:18:24Z"
id: 292095
url: "https://caidehen.iteye.com/blog/292095"
---

Liquid is a safe way to provide a powerful template language to the site's users. See how in this episode.


```java
<!-- pages/show.html.erb -->
<%= liquidize @page.content, 'page' => @page %>

# environment.rb
config.gem 'liquid'

# application_helper.rb
def liquidize(content, arguments)
  RedCloth.new(Liquid::Template.parse(content).render(arguments, :filters => [liquidfilters])).to_html
end

# lib/liquid_filters.rb
module LiquidFilters
  include ActionView::Helpers::NumberHelper
  
  def currency(price)
    number_to_currency(price)
  end
end

# category.rb
liquid_methods :name

# page.rb
liquid_methods :products

def products
  Product.all
end

# product.rb
liquid_methods :name, :price, :category
```