Jump to content
kkalgidim

input urlsegment problem

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. 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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?

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...