Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File path in twig #234

Open
deviprsd opened this issue Mar 13, 2016 · 6 comments
Open

File path in twig #234

deviprsd opened this issue Mar 13, 2016 · 6 comments

Comments

@deviprsd
Copy link
Contributor

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.

@bytehead
Copy link
Member

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

@deviprsd
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@jstoeffler
Copy link

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

@deviprsd
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants