Asset_hash and the invocation of asset paths

Hello!

I have a text/css file in the sitemap with the Path stylesheets/branding.css and the Build Path (for instance) stylesheets/branding-663bb1d3.css.

I also have an image/svg+xml file, fleuron.svg which needs to reference this path inside of an xml-stylesheet element,

<?xml-stylesheet href="#{}" ?>

Inside of the layouts/layout.haml file, I’m able to reference this stylesheet simply:

= stylesheet_link_tag :branding

but I can’t use that to invoke an xml-stylesheet.

What is the right way for me to invoke the build path of this file inside the interpolation? Any help is appreciated! If I’m misunderstanding something, please, let me know!

Thanks,

Jonathan Caprell

Edit: I was able to piece together a solution.

Middleman helpers are based upon Padrino helpers. This piece of documentation references an asset_path helper in Padrino, which I was able to invoke in this way:

-# source/images/fleuron.svg.haml

…

<?xml-stylesheet href="#{ asset_path(:css, :branding) }" ?>

…

This gave me exactly what I was looking for upon build,

<?xml-stylesheet href="/stylesheets/branding-663bb1d3.css" ?>

I use:

<?xml-stylesheet href="<%= url_for "/stylesheets/visual.css" %>" media="print,screen"?>

Seems to wrk fine with asset hashes.

Thanks so much! I had actually fixed this a different way and edited my post, and then forgotten to save my edit like an idiot.

I had tried to use url_for shortly after making this thread, and couldn’t make it work—it turns out, I had forgotten the leading /; after reading your post, I went back and tried url_for with the leading / and it totally works just as you said.