Liquid - form helpers? multiple liquid templates?


#1

Hi,

Its taking me a long time to get my head around the Liquid plugin. I
have a couple of questions which hopefully someone can help me with…

  • How difficult would it be to add some kind of Filter or Tag which
    would allow other Liquid templates to be included into the current
    Liquid template (eg. similar to render(:file => “filename”)

  • How difficult would it be to add Filters to provide the usual form
    helper functionality?

Thanks,
Estelle.


#2

Checkout the source of technoweenie’s mephisto, AFAIK you find there
examples for both of your questions

http://techno-weenie.net/svn/projects/mephisto/


#3

Hi Estelle, I am working on a similar problem, if you would like to swap
notes let me know.


#4

I wouldn’t mind seeing your notes too? :slight_smile:

Why not share the notes with everyone!

-Nb

 Nathaniel S. H. Brown                           http://nshb.net

#5

Of course!
But I have no notes yet…
Sometimes you dont wanna hastle the list with lots of little questions
and just working with someone else is easier until you have some good
info to pass on :slight_smile:

Nathaniel B. wrote:

I wouldn’t mind seeing your notes too? :slight_smile:

Why not share the notes with everyone!

-Nb

 Nathaniel S. H. Brown                           http://nshb.net

#6

Its taking me a long time to get my head around the Liquid plugin. I
have a couple of questions which hopefully someone can help me with…

Thanks for checking it out.

  • How difficult would it be to add some kind of Filter or Tag which
    would allow other Liquid templates to be included into the current
    Liquid template (eg. similar to render(:file => “filename”)

I have been toying with the idea of allowing includes in a similar way
rail’s partials work. The issue here is the scope. Liquid is meant for
to be used in very specific areas where you want to allow your users
to change the appearance of aspects of your web application. Allowing
includes of any kind would have to happen through a highly managed and
restricted interface. Additionally not all people who use liquid
render the templates from the file system. You can just as well render
templates from the DB. Where would it look for the included files in
this case: DB or FS?

  • How difficult would it be to add Filters to provide the usual form
    helper functionality?

Filters and helpers are similar things but not quite the same. Filters
only act on data which is passed to them, they cannot be called stand
alone in the current liquid implementation.

This is a limitation which liquid inherited from django templates. I’m
not terribly happy with myself. It works quite well but If you
approach, as most people do, with a rails background it seems
backwards.

In shopify we use filters like this:

{{ product.url | link_to: ‘Cool Product’ }} #=> <a
href="/products/cool-product" title="Cool Product>Cool Product

{{ product.feature_image | product_image: ‘small’ }}
{{ ‘shop.css’ | assets_url | stylesheet_link_tag }}
{{ ‘shop.js’ | assets_url | javascript_source_tag }}

You always start with the core information on the left and run it
through filters to get the desired result.

Thanks,
Estelle.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Tobi
http://shopify.com - modern e-commerce software
http://typo.leetsoft.com - Open source weblog engine
http://blog.leetsoft.com - Technical weblog


#7

Tobias - Thanks for the info!

I haven’t decided whether I want to store templates in the database or
filesystem. I was leaning towards filesystem, but if the database is
easier then I can probably do that instead.

The main thing is that I need to be able to include multiple template
files into one larger file, similar to how the rhtml layout files
work. Liquid templates look fantastic for my purposes, but without
this functionality I can’t possibly use Liquid templates. Could you
offer any suggestions as to how I could have one master layout page
(ideally Liquid, but possibly could be rhtml instead) and include
multiple Liquid templates to form the final page? (This is probably
easy, but I’m still a newbie!)

I also couldn’t figure out how to define my own Filters (when using
Liquid templates in the filesystem in place of rhtml files). I was
using the info in the Liquid wiki, but I still couldn’t get it to
work. But, I’m sure this can’t be hard so I’ll just have another look
into it. (On a side note, I think the installation of Globalize may
have caused Liquid templates to no longer work, or vice versa… yay)

Kris - contact me anytime, but there’s a few other things I need to
work on first so it may be some time before I’ve made any progress
with incorporating Liquid templates into my app. If I figure anything
out i’ll be sure to let you guys know :slight_smile:


#8

Make application.liquid and put {{ content_for_layout }} somewhere in it
and it will insert the liquid view in the layout just like normal
rthml’s.

K


#9

On 2/17/06, jezari designs removed_email_address@domain.invalid wrote:

offer any suggestions as to how I could have one master layout page
(ideally Liquid, but possibly could be rhtml instead) and include
multiple Liquid templates to form the final page? (This is probably
easy, but I’m still a newbie!)

Currently you can use liquid for layouts just like you can rhtml.
Maybe thats what you need?

I also couldn’t figure out how to define my own Filters (when using
Liquid templates in the filesystem in place of rhtml files). I was
using the info in the Liquid wiki, but I still couldn’t get it to
work. But, I’m sure this can’t be hard so I’ll just have another look
into it. (On a side note, I think the installation of Globalize may
have caused Liquid templates to no longer work, or vice versa… yay)

You can create filters in your helpers file. In the first parameter of
the methods you will get the string representation of the left side of
the filter.

Kris - contact me anytime, but there’s a few other things I need to
work on first so it may be some time before I’ve made any progress
with incorporating Liquid templates into my app. If I figure anything
out i’ll be sure to let you guys know :slight_smile:


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Tobi
http://shopify.com - modern e-commerce software
http://typo.leetsoft.com - Open source weblog engine
http://blog.leetsoft.com - Technical weblog


#10

“I have been toying with the idea of allowing includes in a similar way
rail’s partials work.”

This would be good. I think the ability to use components would be even
better so you can call an action and get the results as liquid code - a
good example being getting a menu for the currently logged in user.