Jump to content

Using A Child Templae As URL Variable, Without Loading the Child Page


John W.
 Share

Recommended Posts

Hi,

I've set up a structure like so:

842507936_ScreenShot2019-09-18at11_33_36AM.png.5718819b5136c9e2f8ea66fb38c16168.png

 

these are the templates

documents -> documents_category -> documents_document

 

Basically, when someone goes to /documents/ it creates a listbox of categories and the page then lists all the documents_document in that documents_category.

In my listbox, I have the url value set to /documents/document_category

for instance /documents/human-resources/ would list all the documents contained under human-resource.

Herein is the problem, I just want to use the human-resources as a url parameter to pass to /documents/ rather than processwire trying to load an actual page at /documents/human-resources/documentname

Right now, it goes to /documents/human-resources/documentname/

Is there a way to set processwire to treat human-resources as a url parameter and not attempt to load the child page /documentname/?

 

 

Note, I added a path like /documents/results/document-category/ which works, however, I need this to work in the back-end when using a page select field.

The only solution I could think of was creating a documents_category.php file that takes the url, /documents/document-category/ and changes it to /documents/results/document-category/ then does a session redirect. Using this  a page select would go to /documents/document/category/ which inserts the "/results/" segment and then redirects to /documents/results/category-name

 

Thanks!

 

 

 

Link to comment
Share on other sites

/documents/human-resources/ is a page accessible because it has a template file and is published. 

If you set, to its children, a template that does not have a template file (.php), they will not be accessible directly. So you can use the API to get their content and show to the user. 

So:

/documents/human-resources/ works

/documents/human-resources/document-name will get a 404

 

  • Like 1
Link to comment
Share on other sites

Yeah, I understand that. I had to create a page for the document-name, simple php file that redirects to documents/results/human-resources/

my documents.php then pulls the 3rd url segment and uses that for my $pages-find() query to filter results  

It works. Just figured there might be another way. 

Link to comment
Share on other sites

2 hours ago, John W. said:

Yeah, I understand that. I had to create a page for the document-name, simple php file that redirects to documents/results/human-resources/

Actually is the other way around, the document template should NOT have a PHP file.

So on the Human Resource page, you can loop though its children and display the info you need. I guess is the document title, link to download etc. 

Link to comment
Share on other sites

Yup, that is what I'm doing. However, the trouble is I'm using a Page Reference field in another template, which creates a link like /documents/document-category/nameofdocument

Of course, it throws a 404, since "nameofdocument" doesn't exist.

So, what I did, for "nameofdocument", I created a php file for that template that redirects to /documents/results/document-category/.  Since /documents/results/ doesn't have a template it just treats results/ like a url segment. ?

Link to comment
Share on other sites

5 hours ago, John W. said:

my documents.php then pulls the 3rd url segment and uses that for my $pages-find() query to filter results

So the $pages->find finds the page in the 3rd url segment and displays the content of that page? I guess I don't understand why that is better than having a template file for the document template - I am sure I am missing something, but maybe if you could better explain what you are actually trying to accomplish by doing it this way we might be able to offer some other/better alternatives.

  • Like 1
Link to comment
Share on other sites

On 9/18/2019 at 9:48 PM, adrian said:

So the $pages->find finds the page in the 3rd url segment and displays the content of that page? I guess I don't understand why that is better than having a template file for the document template

I don't have a php template for documents.  The non-php template, for documents just holds a title, summary and has pdf attachments available for download.

Therefor, when /documents/ does a query, it finds all the "document" templates and lists them with a title, summary, and links to either view or download a pdf.

See this screenshot:

/documents/ simply does a list like this where visitors can see a date, title, summary and download or view pdf files. the information for each entry is a php-less template with date, title, summary and a file-type pdf field for attaching the pdf.

493784289_ScreenShot2019-09-21at10_29_38AM.thumb.png.812936e7921bb108fe4828b1e150ebdd.png

Link to comment
Share on other sites

@John W. - I understand the way the documents template works - to load a summary list of documents, but I still don't understand the problem with PW trying to load the individual document when the document is in the URL - how do users end up with the document component in the URL and what are they supposed to see when it is?

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