How to get current context within a template

21 views
Skip to first unread message

Amitava Shee

unread,
May 26, 2011, 4:25:37 PM5/26/11
to middlem...@googlegroups.com
Is there a way to get access to the current context within a template?

For example, I need to access the name of the template being rendered from within a partial. This is in an attempt to create a pager control that has "Previous" and "Next" buttons.

Thanks in advance,
Amitava Shee

Amitava Shee

unread,
May 27, 2011, 1:31:24 PM5/27/11
to middlem...@googlegroups.com
After some digging, I am able to gather the following

1. Every template is passed an object scope#Middleware::Server and local#Hash
2. request is available (as part of being Rack middleware). I ended up using request.path . Here's a request object instance from my app

#<Sinatra::Request:0x00000103de5630
 @env=
  {"rack.version"=>[1, 1],
   "rack.input"=>#<StringIO:0x00000103de6030>,
   "rack.errors"=>#<StringIO:0x00000103de60d0>,
   "rack.multithread"=>true,
   "rack.multiprocess"=>true,
   "rack.run_once"=>false,
   "REQUEST_METHOD"=>"GET",
   "SERVER_NAME"=>"example.org",
   "SERVER_PORT"=>"80",
   "QUERY_STRING"=>"",
   "PATH_INFO"=>"/tutorials/measles/mmr06.html",
   "rack.url_scheme"=>"http",
   "HTTPS"=>"off",
   "SCRIPT_NAME"=>"",
   "CONTENT_LENGTH"=>"0",
   "rack.test"=>true,
   "REMOTE_ADDR"=>"127.0.0.1",
   "HTTP_HOST"=>"example.org",
   "HTTP_COOKIE"=>"",
   "rack.request.query_string"=>"",
   "rack.request.query_hash"=>{}},
 @params={},
 @route="/tutorials/measles/mmr06.html">

-Amitava

Thomas Reynolds

unread,
May 27, 2011, 1:41:08 PM5/27/11
to middlem...@googlegroups.com
Nice work. There's not a ton of blog posts or articles about Middleman online, but it is just Sinatra so it's always helpful to google that when looking for a solution.

-Thomas
Reply all
Reply to author
Forward
0 new messages