Jump to content

Recommended Posts

Posted

Greetings,

I wonder if someone can help me with this issue. I am trying to use a file uploaded via backoffice in a template file but with no success. I am using the same sintax as images, but it seems it doesn't work:

$image = $page->images->getRandom(); // this works
$file = $page->files->getRandom(); // this doesn't

I've tried pop(), first() and other functions but I believe I must be missing something.

Thanks for everything.

Posted

I also can't find any example (been looking a lot through the site and forum) regarding file upload and listing them afterward in a page. Could anyone point me in the right direction, please?

Posted

Got it. The problem was related to the fact I only uploaded one file and it seems that when only one file is uploaded, I cannot refer to the field content as an array. This means that this is enough:

$file = $page->files;

I knew this was a simple thing.

Posted

You changed a lot since the last time :D

Glad it's working, but I think it shouldn't work like this. The normal behavior is that it isn't considered an array only if the limit of files is set to one, and not if there's only one file uploaded. Can you check this?

  • Like 1
Posted

I confirm that the limit is set to 1. First time I tested that limit so it was confusing.

Thanks again, Diogo. Almost finishing my first PW project for a client! ;)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...