More NHaml questions

0 views
Skip to first unread message

Paul Wideman

unread,
Apr 16, 2008, 11:42:30 PM4/16/08
to mvccontrib-discuss
Haml, and by extension NHaml, is beautiful and I would love to use it
in a current project. But there are a couple of hangups that I can't
seem to get past:

1) How do I insert a tag in the middle of some text, without adding
the line breaks? I realize that for a simple tag I can do something
like:

%label <em>U</em>sername:

But if the tag I want to embed is more complicated, like say a link
that I want to create using the Html helper methods, I'd rather not
enter it directly like above. Is there any way to do something like:

%p [a whole bunch of text] + Html.ActionLink(...) + [some more text]

?

2) I understand how partials work, but is there any way to create a
reusable component that can be used by views rendered by actions in
different controllers? The partials seem to be limited to the views
contained in their directory.

3) Is there any way for a view to insert content into elements that
are rendered by the layout? For instance, if a view needs to include a
certain javascript or css file, or add some script, I'd like for those
tags to go in the head, not in some arbitrary location in the body
markup.

I've fallen in love with the Haml syntax and I really want to use it,
but I can't seem to get past these sticky points.

Thanks,
pw

Andrew Peters

unread,
Apr 17, 2008, 12:54:05 AM4/17/08
to mvccontrib-discuss
> 1) How do I insert a tag in the middle of some text, without adding
> the line breaks?

%p= "Foo" + Html.ActionLink(...) + "Bar"

> 2) I understand how partials work, but is there any way to create a
> reusable component that can be used by views rendered by actions in
> different controllers?

This currently not supported but should be. It should work like this:

_ Shared\Foo

Where Shared is the name of a folder under Views. Feel free to
contribute a patch :-)

> 3) Is there any way for a view to insert content into elements that
> are rendered by the layout?

No. One approach is to have the Controller set some ViewData that
controls what happens in the Layout.

Cheers,

Andrew.

Paul Wideman

unread,
Apr 17, 2008, 11:06:59 AM4/17/08
to mvccontrib-discuss
> %p= "Foo" + Html.ActionLink(...) + "Bar"

OK, is it possible for "Foo" and "Bar" to span multiple lines? The
example I have in mind is a link in the middle of a large paragraph.
I've tried different combinations of using the pipe but nothing seems
to work.

> This currently not supported but should be. It should work like this:
>
> _ Shared\Foo
>
> Where Shared is the name of a folder under Views. Feel free to
> contribute a patch :-)

I may look into it. I've also toyed with the idea of an NSass view
engine, or at least a controller that parsed sass files and handed a
collection of css rules to a normal view to render.

Thanks.

Andrew Peters

unread,
Apr 17, 2008, 11:57:27 PM4/17/08
to mvccontrib-discuss
Hi Paul,

Today I committed fixes to both issues:

1) Partial resolution now looks in the parent folder which enables the
_ Shared\Foo scenario
2) I "fixed" how the multiline operator works so it is now more like a
proper line continuation character, so this works:

Foo |
%a{href = '#'} Bar |
Baz

Which outputs as:

Foo <a href="#">Bar</a> Baz

Feedback on this appreciated.

Cheers,

Andrew

Paul Wideman

unread,
Apr 19, 2008, 1:16:23 AM4/19/08
to mvccontrib-discuss
Both look good, I responded to your other post about the new line
continuation change with a few nit picky issues.

On Apr 17, 10:57 pm, Andrew Peters <andrew.john.pet...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages