Jump to content

Recommended Posts

Posted

I wish to show various bits of information on a File repeater (extension, filesize etc).

The filename shows correctly, but the links to the files open the admin area, the file extension is empty and the filesize too.

function renderDocumentLibrary($page) {
$out = "";
if ($page->document_download->count()) {
print_R($page);
$out .= "<div class='row downloads'>";
foreach($page->document_download as $download) {
$out .= "<div class='col-xs-12 col-sm-6'>";
$out .= "<div class='download clearfix'>";
$out .= "<a href='{$download->url}'><img src='{$download->ext}' alt='Download {$download->document_name}' class='download-icon' /></a>";
$out .= "<div class='download-content'>";
$out .= "<span class='download-date'>" . date('d.m.y', $download->modified) . "</span><br />";
$out .= "<h2 class='h4'>{$download->document_name}</h2>";   
$out .= "<a href='{$download->url}' class='download-link'>Download {$download->ext} ({$download->filesizeStr})</a></div>";
    $out .= "</div></div>";
  
}
$out .= "</div>";
}
return $out;
}

Can I access those attributes in this way?

Posted

You need to specify the name of the file field used in the repeater (each repeater item is technically a page). Thus, iterating over $page->document_downloads returns pages and you need to explcitly state which field of that page you want to access, just like with a regular page.

foreach($page->document_download as $download) {
    $file = $download->name_of_your_file_field;
    $fileurl = $file->url;
}
  • Like 1

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...