Hommer Smith
Hommer Smith

Reputation: 27852

Passing liquid file to Liquid::Template.parse

Right now I am able to do this:

@template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template
p @template.render('name' => 'tobi')

However, how can I call Liquid::Template with a file that I have called template.liquid that has the content:

hi {{name}}

Upvotes: 1

Views: 1929

Answers (1)

7stud
7stud

Reputation: 48599

File.read() returns the whole file as a string, so you can write:

template = Liquid::Template.parse(
             File.read("template.liquid")
           )

Upvotes: 2

Related Questions