webhoes Posted October 6, 2017 Share Posted October 6, 2017 Hello, I have 2 page type: Books and reports. A report can be link to a book. There is only 1 document (pdf) in a report. I can get the list of linked reports on the book page. But I can not get it to give me the download url. If I use the same field (annual_report) as part of the book template, all works flawlessly. But I need to have the report as a seperate entity. Why doesn't this work? $reports = ''; foreach ($page->annual_report as $report){ $reports .= '<a href="' . $report->url . '" class="download-btn" target="_blank"><i class="fa fa-file-pdf-o" aria-hidden="true"></i>' . $report->description . '</a>'; } //this doensn''t work, but should be correct $ann = ''; $annual = $pages->find("template=annual-report, studbook=$page->id"); foreach($annual as $a){ $ann .= '<a href="' . $a->annual_report->url . '" class="download-btn" target="_blank"><i class="fa fa-file-pdf-o" aria-hidden="true"></i>' . $a->annual_report->description . '</a>'; } Link to comment Share on other sites More sharing options...
DaveP Posted October 6, 2017 Share Posted October 6, 2017 What happens if you echo $annual? 1 Link to comment Share on other sites More sharing options...
webhoes Posted October 6, 2017 Author Share Posted October 6, 2017 It shows the array of the found reports, as expected. 1105|1106 Link to comment Share on other sites More sharing options...
webhoes Posted October 6, 2017 Author Share Posted October 6, 2017 studbook=$page->id is old... studbook=$page->title what I use... I changed this for one of the tests. I also tried to build up the path to the document with this. $path = $a->annual_report->url; $path .= $a->annual_report->name; $path .= '.' . $a->annual_report->ext; But also this only shows the directory where the pdf resides. Nothing about the pfd itself. Link to comment Share on other sites More sharing options...
abdus Posted October 6, 2017 Share Posted October 6, 2017 3 minutes ago, webhoes said: But also this only shows the directory where the pdf resides. Nothing about the pfd itself. This means you've set up the file field to give you an array of files (Pagefiles), you need to get the file using annual_report->first->url. Using annual_report->url gives you the directory. You can limit field to 1 file and return you a Pagefile object instead of an array (Pagefiles) too 2 Link to comment Share on other sites More sharing options...
DaveP Posted October 6, 2017 Share Posted October 6, 2017 1 minute ago, abdus said: This means you've set up the file field to give you an array of files (Pagefiles), you need to get the file using annual_report->first->url. Using annual_report->url gives you the directory See $files vs $file http://cheatsheet.processwire.com/ 2 Link to comment Share on other sites More sharing options...
webhoes Posted October 6, 2017 Author Share Posted October 6, 2017 @abdus you're right. The other field had a max of 1 on it. This field not. I got it working now. Thanks. I totally overlooked this myself. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now