When I first started integrating Twig into my project I was annoyed with
that way that path resolution works when including resources with tags like
include and macro. Paths were always resolved relative to the working
directory of my project so I always had to write out the full path to a
template even if it existed in a single subdirectory of the currently
rendering template. To combat this I decided to automatically change the
working directory to the path of the template being rendered immediately
before calling render(). This strategy worked but now I find myself wanting
to be able to render 'absolute' paths too. Ideally I want to be able to
resolve both relative and 'absolute' paths such that a scheme beginning
with a '/' would be treated as 'absolute' and resolved in the context of my
view script root directory and any other path would be resolved in the
context of the currently rendering template's directory.
What would be the best way to implement this path resolution strategy
within Twig?