开发者

Only include namespace declarations on particular HAML pages using rails

开发者 https://www.devze.com 2023-02-07 19:37 出处:网络
I have a Rails app (v2.3.8) using HAML (v3.0.25).My application.html.haml currently has the following facebook namespaces declared at the top, specifically for开发者_Python百科 FBLike in a child page:

I have a Rails app (v2.3.8) using HAML (v3.0.25). My application.html.haml currently has the following facebook namespaces declared at the top, specifically for开发者_Python百科 FBLike in a child page:

!!! 5
%html{:lang => 'en', 'xmlns:og' => 'http://ogp.me/ns#', 'xmlns:fb' => 'http://www.facebook.com/2008/fbml' }
  %head
    ...

Is it possible to remove the facebook declaration from the application.html.haml & only declare it in my childpage.html.haml, where the FBLike & meta tags are? I would also like to keep the :lang => 'en' where it is at the moment; I don't want to declare it again in all pages.


You can always make a different layout for FBML pages that has this namespace header. It's also possible to create a view helper named something like html_tag_attributes and use that instead:

%html{ html_tag_attributes }

You'd define that as roughly:

DEFAULT_HTML_ATTRIBUTES = { :lang => 'en', 'xmlns:og' => 'http://ogp.me/ns#' }
DEFAULT_FBML_ATTRIBUTES = DEFAULT_HTML_ATTRIBUTES.merge('xmlns:fb' => 'http://www.facebook.com/2008/fbml')

def html_tag_attributes
  @use_fbml ? DEFAULT_FBML_ATTRIBUTES : DEFAULT_HTML_ATTRIBUTES
end

You can customize this to have the behavior you want instead of the simple instance variable test.

0

精彩评论

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