OneupUploaderBundle icon indicating copy to clipboard operation
OneupUploaderBundle copied to clipboard

File path in twig

Open deviprsd opened this issue 9 years ago • 6 comments

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.

deviprsd avatar Mar 13 '16 23:03 deviprsd

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 }}" />

bytehead avatar Mar 14 '16 09:03 bytehead

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.

deviprsd avatar Mar 14 '16 14:03 deviprsd

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.

deviprsd avatar Mar 18 '16 22:03 deviprsd

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

deviprsd avatar Mar 19 '16 00:03 deviprsd

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 avatar May 30 '16 10:05 jstoeffler

@jstoeffler Try the gist I suggested for the time being if you want to, https://gist.github.com/deviprsd21/5bd4bc827ee7991640c4

deviprsd avatar May 30 '16 12:05 deviprsd