Trying to reference an attached file within a page template

What is the proper way to include a file attachment in a content_item, and then link to that file in a page template?

For example – I have a Resource content_type. Each Resource content_item is associated with a PDF file. Rather than have a user load a PDF file separately, then reference its file-name within the Resource content_item, I want to allow them to attach the PDF to the Resource item itself. This will also keep things neater inside the CMS, as my users tend to place random files all over the place.

The problem is … I have no idea how to access information about that attached PDF file in the Resource content_item’s template – I don’t know where it resides on the server, I don’t know its filename, etc. I try using variations of $rx.generate.location … but that doesn’t seem to work when you’re dealing with a file stored in an attribute of another content_item, rather than it being its own content_item itself.

Is there a standard way of approaching this problem? Or is it better to upload the PDF as a separate file, and then reference it in the item in some other way, such as a string attribute that must be entered manually (a slot is a no-go, b/c my users are not capable of dealing with Active Assembly)?

This is a late reply, so apologize if you have solved this already, but the simplest way I can think of approaching this problem would be to create a second Page template for your resource content type that uses the Binary Assembler / Output Binary Page that will be tasked with rendering/assembling the file field. Set that template to Always publish, and create a location scheme in both your Delivery and Assembly contexts for it that handles building the filename for the PDF from your resource content type’s fields.

Given that setup, $rx.location.generate should work for you if you pass the binary template name in as a parameter when generating the link.

-n

Thanks, Nate. It has been a while since I was trying to solve this problem. I’m going to give it another go using your advice during my next development cycle.