OneupUploaderBundle
OneupUploaderBundle copied to clipboard
File path in twig
How will I get the file path in twig? I previously used viichuploader, and it had a twig function to generate the file url! I don't want to save the file path in the database, to save database size.
As easy as it can get! :) You don't have to store the whole path.
Just configure your upload directory:
oneup_uploader:
mappings:
gallery:
storage:
filesystem: %kernel.root_dir%/../web/uploads/gallery
and in twig you can use it like this:
<img src="/uploads/gallery{{ image.path }}" />
I wanted a more dynamic way, like maybe a twig function, but then I realized I will be using LiipImagineBundle so, ill be using its function. Thanks anyway.
I thought about it again, i want to make this as a feature request. The way you suggested is easy, but it isn't much helpful if i were to change the directory. I would have to edit everywhere else, one by one. A function that can do this procedure you suggested without anyone having to do it. It would be nice, I guess.
And suppose you say no to this, here is a gist I created that you can refer to people at least who would want it. This shows how to create a helper function for controller and twig. I hope you don't mind. https://gist.github.com/deviprsd21/5bd4bc827ee7991640c4
I'd also be interested in this, I'dl like to crop the image after it's been uploaded, and the cropper I use needs the filer URL, so I'd like to have it in the response object. It would be neat to have a helper that can generate the asset URL directly from the file
@jstoeffler Try the gist I suggested for the time being if you want to, https://gist.github.com/deviprsd21/5bd4bc827ee7991640c4