#1 December 14, 2018 4:54am

Terrra-Robin
Member
Registered: February 7, 2016
Posts: 61

Multiple levels of routed templates

Hi,

I got a question about routed templates and sub items.

Currently I have a module that consist of different items. Under these items, there are sub items.
These sub items are linked via a one to many field.

So there are 2 overview pages. One with the main items, and one with the corresponding sub items.
The main item can be either one level deep, or 2 levels (if it has sub items).

Right now I don't know how to link these 2 modules to have a nice url (and breadcrumb).
For example, I have "athmospheric pictures" and beneath that are "night photograpgy" and "black and white phptpgraphy".
If you go to the "athmospheric pictures" page, the url is "portfolio/landing/athmospheric pictures" to have a different template as a normal item.
A normal item's link would be "portfolio/item/black and white phptpgraphy". But this doesn't have the "athmospheric pictures" inside the url.

Is it possible to make a routed template that has "portfolio/athmospheric-picures/black and white phptpgraphy" as a url?

What would be the right way to do this?

The story about the links could be a bit vague without seeing it.
This is where you can see what I mean https://zpam.nl/portfolio

Many thanks in avance

Offline

#2 December 14, 2018 1:42pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Multiple levels of routed templates

Yes, you can do that. What I would do is do a check in your routed template's default.php to see how many additional commands are present. Something like this:

if (count($bigtree["commands"]) == 2) {
   include "sub-item.php";
} else if (count($bigtree["commands"]) == 1) {
   include "item.php";
} else {
    // The landing page is here.
}

Then in sub-item.php you'll want to do a look-up on the top-level item based on the first route in $bigtree["commands"] and look up the sub item based on the second route and make sure that the sub-item is a child of the top-level item (and if it is not, throw a 404).

In item.php you'd just do what you're likely doing now which is just look-up the item by $bigtree["commands"][0].

Offline

#3 December 15, 2018 10:50am

Terrra-Robin
Member
Registered: February 7, 2016
Posts: 61

Re: Multiple levels of routed templates

timbuckingham wrote:

Yes, you can do that. What I would do is do a check in your routed template's default.php to see how many additional commands are present. Something like this:

if (count($bigtree["commands"]) == 2) {
   include "sub-item.php";
} else if (count($bigtree["commands"]) == 1) {
   include "item.php";
} else {
    // The landing page is here.
}

Then in sub-item.php you'll want to do a look-up on the top-level item based on the first route in $bigtree["commands"] and look up the sub item based on the second route and make sure that the sub-item is a child of the top-level item (and if it is not, throw a 404).

In item.php you'd just do what you're likely doing now which is just look-up the item by $bigtree["commands"][0].

Ofcourse! Including instead of using a new template each time!
Thanks a lot. It's working and my code is a lot cleaner and less complicated now smile

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.