Getting Url From Field Type
Created 6 years ago by richardoctoey

hi guys, I have problems when showing url, I use {{ page.header_image.url }} but the results is: http://localhost:8000/\app/default/files-module/local/images/banner-ourpage.jpg Why I get the backslash in the url? It will be ok if no backslash I'm using windows and pyrocms 3.3

ryanthompson  —  6 years ago Best Answer

Actually.. I @richardoctoey I just noticed this is not making it into the Image class which is what I was assuming earlier. It was in the files adapter. Your code was fine but I just realized there was a bug there for windows machines. This should fix it: https://github.com/anomalylabs/local_storage_adapter-extension/commit/151b53be442e1851f2bd8a3b06b84cdbaeef9907

But to echo what @oimken suggested I would lean on paths rather than absolute URLs whenever possible which all the route() method do as does {{ page.header_image.make.path }}. Note that cause you use make you are now accessing an image instance: https://pyrocms.com/documentation/streams-platform/latest#services/image

oimken  —  6 years ago

try {{ page.header_image.viewPath()|raw }}

ryanthompson  —  6 years ago

Checkout the comment I left on Stackoverflow too but I wonder if there is a bug somewhere..

Generally though I would personally use {{ page.header_image.route('view') }} or {{ page.header_image.route('download' }} for example.

ryanthompson  —  6 years ago Best Answer

Actually.. I @richardoctoey I just noticed this is not making it into the Image class which is what I was assuming earlier. It was in the files adapter. Your code was fine but I just realized there was a bug there for windows machines. This should fix it: https://github.com/anomalylabs/local_storage_adapter-extension/commit/151b53be442e1851f2bd8a3b06b84cdbaeef9907

But to echo what @oimken suggested I would lean on paths rather than absolute URLs whenever possible which all the route() method do as does {{ page.header_image.make.path }}. Note that cause you use make you are now accessing an image instance: https://pyrocms.com/documentation/streams-platform/latest#services/image

richardoctoey  —  6 years ago

@ryanthompson allright thankyou mate @oimken thanks mate. For thoose who want simple answer may use oimken way