Jump to content

input urlsegment problem


kkalgidim
 Share

Recommended Posts

Hi,

I m confused on how to filter results using url segment. It must be very easy question but i can not figure it out. 

Here is my admin tree

Home

  • Clinics
    • Clinic1
    • Clinic2
  • Treatments
    • Dental Implant
    • Hair Transplant
  • Locations
    • Turkey
    • Mexico
    • Germany

 

I am using location template, treatment template, clinic template

My question is

How can i create a link on location template to show the clinics on that location.

For ex: on the www.xxx.com/locations/turkey  url i have a button called clinics. When i click on that button i want to goto www.xxx.xom/locations/turkey/clinics and it will show the clinics located on Turkey.

I hope my explanation clear. 

Link to comment
Share on other sites

I was assuming you only have a one-to-one relationship when I quickly wrote this, so you'd probably have to slightly alter this basic code:

if($input->urlSegment1) {
	$seg = $sanitizer->name($input->urlSegment1);
	if($seg === 'clinic') {
		$loc = $page->name;
	}
	$clinic = $pages->get("template=clinic, location=$loc");
	$content .= "<p><a href='{$clinic->url}'>{$clinic->title}</a></p>";
}

 

  • Like 1
Link to comment
Share on other sites

one-to-many would look something like this

if($input->urlSegment1) {
	$seg = $sanitizer->name($input->urlSegment1);
	if($seg === 'clinics') {
		$loc = $page->name;
	}
	$clinics = $pages->find("template=clinic, location=$loc");
	foreach($clinics as $clinic) {
		$content .= "<p><a href='{$clinic->url}'>{$clinic->title}</a></p>";
	}
}

e.g. a location can have multiple clinics

  • Like 2
Link to comment
Share on other sites

Thanks for reply @dragan

it will be one-to-many relationship

there is 2 template file location.php and list.php

 xxx.com/location/turkey/  uses location.php template

when i enter xxx.com/location/turkey/clinics i want to use list.php template 

because list will be new designed page. not the part of location template design. how can i achive this?

So there is 2 question.

1. how can i assign list template with xxx.com/location/turkey/clinics

2. same code works on list.php template?

 

 

 

 

 

 

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