Jump to content

Get description from File field


felted
 Share

Recommended Posts

Hi,

i created a repeater-field with an file-field in it.
I get the filename with this code:

foreach ($page->Downloads as $download) {
	$ext = pathinfo($download->Datei, PATHINFO_EXTENSION);
	$content .= "<i class='material-icons mr-2 float-left'>save_alt</i>";
	$content .= "<a target='_blank' href='".$download->Datei->url.$download->Datei."'>".$download->Datei->Beschreibung."</a> <span class='btn-secondary pl-1 pr-1'>".$ext."</span><br />";
}

But i cant get the description (Beschreibung) from the file-field.

Can anybody help me?

Thanks, Felted

repeater_file_description.jpg

Link to comment
Share on other sites

The machine names of system fields are always in english, so you need to access the description like this:

$description = $download->Datei->description();

By the way, there's also a utility method for the file extension:

$extension = $download->Datei->ext();

Also, if your Repeater only contains the file field, you could also get rid of the Repeater altogether and just allow multiple files on the "Datei" field. Then you could iterate it directly:

foreach ($page->Datei as $file) {
    $url = $file->url();
    $ext = $file->ext();
    $description = $file->description();
    // output download links here ...
}

Look up the Pagefile API documentation for a list of all available utility methods.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...