Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Current Path of Page in Middleman Layout File

Tags:

ruby

middleman

Is it possible to retrieve the current path of a page in a middleman file? For instance, if I have a layout file layout.erb with something like the following:

<%= page.path %>
<%= yield %>

and a test file index.html:

Testing

then when Middleman rendered the page I would get something like:

/index.html
Testing
like image 741
LandonSchropp Avatar asked May 21 '12 07:05

LandonSchropp


1 Answers

Middleman also provides the current_page variable. current_page.path is the source path of this resource (relative to the source directory, without template extensions) and current_page.url is the path without the directory index (so foo/index.html becomes just foo).

<%= current_page.path %>
# -> index.html

<%= current_page.url %>
# -> /

Details from Middleman's Middleman::Sitemap::Resource rubydoc. http://rubydoc.info/github/middleman/middleman/Middleman/Sitemap/Resource

like image 58
Nick Avatar answered Oct 03 '22 08:10

Nick