我使用“按钮的下拉列表”从Twitter的引导与HAML。 在引导文档我已经找到了例子:
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
Action
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<!-- dropdown menu links -->
</ul>
</div>
我已经尝试过使用HAML改写:
%div{:class => 'btn-group task_controller'}
%a{:class => 'btn-mini dropdown-toggle', "data-toggle" => 'dropdown', :href => '#'} Action
%span{:class => 'caret'}
%ul{:class => 'dropdown-menu'}
%a{:class => 'close_task', :name => task.name, :href => '#' } Close
但得到的错误信息:
Haml::SyntaxError - Illegal nesting: content can't be both given on the same line as %a and nested within it.
因此,引导说我把里面的元素 - 标签,但HAML不允许这样做。 我该如何解决这一问题?
问题是,在这些线路:
%a{:class => 'btn-mini dropdown-toggle', "data-toggle" => 'dropdown', :href => '#'} Action
%span{:class => 'caret'}
该错误消息: content can't be both given on the same line as %a and nested within it
指Action
,这是“在同一行作为一%”的内容,并%span{:class => 'caret'}
,这是内容“嵌套在”。
更一般地,更容易看清也许,你不能有这样的事情:
%tag Some content here
And something here as well
解决方法是窝都下%a
:
%a{:class => 'btn-mini dropdown-toggle', "data-toggle" => 'dropdown', :href => '#'}
Action
%span{:class => 'caret'}
这使所需的输出:
<a class='btn-mini dropdown-toggle' data-toggle='dropdown' href='#'>
Action
<span class='caret'></span>
</a>
不要忘记你的Haml的成语!
#div{:class => 'btn-group task_controller'}
相当于:
.btn-group.task_controller
…等等。
试试这个:
%div{:class => 'btn-group task_controller'}
%a{:class => 'btn-mini dropdown-toggle', "data-toggle" => 'dropdown', :href => '#'}
Action
%span{:class => 'caret'}
%ul{:class => 'dropdown-menu'}
%a{:class => 'close_task', :name => task.name, :href => '#' } Close
标签名称和内容可以在同一条线上,只有当有在标签没有更多的内容行。
文章来源: Haml::SyntaxError - Illegal nesting: content can't be both given on the same line as %a and nested within it