Disable :relative_assets on one page

Hi Guys,

I want to use relative assets in all of my pages, except for one page. I am using cloudfront and S3 to host my page and you can specify a html file that is displayed for 404 and 403 errors.

Since this page could have any random path like /foobar/test/something.html all the links, javascript and stylesheet references have to be absolute otherwise it breaks them.

Unfortunately I have not been able to find a way to disable. I have tried frontmatter, the page directive and even :relative => false on the stylesheet directive, but none of it worked.

Is there a way of doing this?

Greetings, Kim

Seems that

<%= favicon_tag 'favicon.ico', :relative => false %>

or

<%= stylesheet_link_tag "mycss.css", :relative => false %>

ignore the :relative option. Is this for link_to only? There should be some correlation between config options in config.rb:

set :relative_links, true
activate :relative_assets

Apparently they are independent.

yes they are ignored unfortunately. And I want both relative links and assets for my files, except for the error page :frowning:

I havent been able to find a solution so far.

Did anyone ever find a workaround for this?
I would love to be able to use:

relative_assets: false
relative_links: false

in the frontmatter

The newest 3.4.0 version from v3-stable branch has some improvements in this regard. Read this: https://github.com/middleman/middleman/issues/1539

So with 3.4.0 version I’ve made my layout file like this:

  <%= stylesheet_link_tag "my_styles", relative: (not current_page.data.absolute_assets) %>
  <%= javascript_include_tag 'all', relative: (not current_page.data.absolute_assets) %>

And on my 404 page’s frontmatter I have:

absolute_assets: true

Unfortunately it still doesn’t work with image_tag yet, so if you use images on 404 page then you need to manually:

<%= tag :img, src: asset_url('my_image.jpg', 'site_images', relative: (not current_page.data.absolute_assets)), alt: "My image" %>

(site_images is my folder for image assets, as defined in config.rb) It works for link_to though, which is crucial in building menu/navigation.

<%= link_to 'Menu text', 'other_page.html', title: 'Menu item title', relative: (not current_page.data.absolute_assets) %>

Additionally, it doesn’t work yet with favicon helper:

<%= favicon_tag '/favicon.ico', :relative => false  // doesn't work! %>

Thanks @kmor72
I’ve tried your approach on my project but it didn’t work, I’m using middleman 4.2.1 and S3