开发者

Adding a span tag to this menu in rails?

开发者 https://www.devze.com 2023-01-29 18:30 出处:网络
I am unable to add a span tag to the redmine project menu. You can see the full code at the redmine repository under trunk/lib/redmine/menu_manager.rb around line 182. Thi开发者_开发知识库s is the lin

I am unable to add a span tag to the redmine project menu. You can see the full code at the redmine repository under trunk/lib/redmine/menu_manager.rb around line 182. Thi开发者_开发知识库s is the line where I'm trying to add a span tag.

return content_tag('li', render_single_menu_node(node, caption, url, selected))

I tried adding a span tag like this:

return content_tag('li', render_single_menu_node(node, content_tag(:span, caption), url, selected))

but it renders the span tag as text in the browser like this:

<span>Overview</span>

The 'li' renders just fine. Is there a way to add the span tag correctly?


See if this helps:

span_tag = content_tag(:span, caption).html_safe
return content_tag('li', render_single_menu_node(node, span_tag, url, selected))

By default, content_tag will escape any html content. You can use html_safe to prevent a string from being escaped.

On rails 2.3.x, there is no html_safe method, but you can pass an option to content_tag to tell it not to escape its contents:

span_tag = content_tag(:span, caption, {}, false)
return content_tag( 'li', 
                    render_single_menu_node(node, span_tag, url, selected), 
                    {}, 
                    false )
0

精彩评论

暂无评论...
验证码 换一张
取 消