仲介者ファイルでページの現在のパスを取得することは可能ですか?たとえばlayout.erb、次のようなレイアウトファイルがある場合:
<%= page.path %>
<%= yield %>
およびテストファイルindex.html:
Testing
次に、ミドルマンがページをレンダリングすると、次のようになります。
/index.html
Testing
Middlemanもcurrent_page変数を提供します。 current_page.pathはこのリソースのソースパス(テンプレート拡張なしのソースディレクトリに対する相対パス)でありcurrent_page.url、ディレクトリインデックスなしのパスです(したがって、foo/index.htmlちょうどになりますfoo)。
<%= current_page.path %>
# -> index.html
<%= current_page.url %>
# -> /
ミドルマンのMiddleman::Sitemap::Resourcerubydocからの詳細。
http://rubydoc.info/github/middleman/middleman/Middleman/Sitemap/Resource
解決策は次のとおりです。
<%= request.path %>