Jump to content

File (PDF) from Child Pages


Warran
 Share

Recommended Posts

Hi

I've searched the forum for an answer to my question so apologies if this has been answered and I haven't found it. I'm also a newbie so please forgive my ignorance.

This is my problem:

I have child pages and each of the child pages (amongst other things) has a file field with one PDF in it. I'm trying to pull a 'list' of the pdfs from each child page onto their parent page. Using $examplefield->url returns 403 forbidden so I tried using $examplefield->httpUrl but this just returns nothing.

Any help would be appreciated. Here's my code:

$newsletters=$page->children;
					
	foreach($newsletters as $pdf){
					
	$doc=$pdf->newsletterfile;
					
		echo"<div class='news-link'>
			<a href='{$doc->httpUrl}' target='_blank'>				
				<img src='{$pdf->newsletter_thumb->url}' alt='{$pdf->newsletter_thumb->description}' />
				<h3>{$doc->description}</h3>								
			</a>
			</div>";
		
	}

Warran

Link to comment
Share on other sites

Is your file-field configured to have just one file, or multiple? If multiple, you'd have to do $filefield->first()->url

Since you get 403 (forbidden) errors, it's maybe more likely those file-fields are somehow access-protected. Check your access setting of that field and/or template. Do you get these errors also as a logged-in superuser or just as guest?

Do yourself a favor and install Tracy Debugger (if you haven't already). You can then insert breakpoints in your code (similar to console.log() with Javascript), and you'll see more infos and hints about the error(s).

Link to comment
Share on other sites

9 hours ago, bernhard said:

How does that work with Tracy? ? 

Well, maybe "breakpoint" is not the right word, i.e. the code won't stop to process like in JS dev tools. But you can dump all kinds of stuff with d($doc) inside the template. Then you'll quickly see e.g. if a var doesn't contain what you thought it should etc. (null, 0 results, nullpage etc.). I'm sure you used it a million ways...

What's perhaps a bit misleading in Tracy, is that addBreakpoint() is meant to only be used with the performance panel. So yeah, not exactly the same as adding JS breakpoints in frontend-land ?

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