Wild card url http://domain.com/advisor/*

Ideally. I could have the subpage of find in the panel. So advisor/find would have a template assigned. But if template not assigned and domain doesn’t exist. Then it would hit another template.

Use Case: Agent 1, Agent2, Agent 3 all have urls.

http://domain.com/advisor/agent1
http://domain.com/advisor/agent2
http://domain.com/advisor/agent3

The previous site. Which the domains can’t changed used. /find which shows a list of agents. And /agentname which then shows the agent.

So now, if the domain isn’t find. I Would like to use a second template that would format to the agent page.

Basically anything thats not /agent/find would need to redirect to the second template.

I have difficulties following you.

What does advisor show? If advisor is your list of agents, then you could return that page if someone uses advisor/find in the url (using a route).

https://www.andavovacations.com/advisor

select a destination. Like Africa and it sends you to the link below.

https://www.andavovacations.com/advisor/find

It then lists a bunch of agents.

you can click on one, the url changes to

https://www.andavovacations.com/advisor/rosieholliday

But this last link is a wildcard. We don’t store those in Kirby. They come from a webservice. So they could change at any time.

For find. I can create that page in Kirby and post to it. But what about when it’s a wildcard. anything past /advisors that is not a page in Kirby.

// There needs to be an exception too. So the system doesn’t take /find as a wildcard.

I see, what you could do is return the same page (template), but send a variable to the controller that depending on the value of that variable then includes either the snippet for the list of advisors or the single advisor. If value = “find” return list, else return agent.

How to replicate the url?

It must have /find and or the wildcard for the agent. They hand these urls out on their business cards :slight_smile:

Thanks so much

That’s the job of the router

c::set('routes', array(
  array(
    'pattern' => 'advisor/(:any)',
    'action'  => function($uid() {
      // return the $uid variable to your controller, as explained in the docs
     // in the controller, pass to template, in template either return find snippet, or agent snippet
    }
  )
));

Any idea how to code this? I haven’t worked in routing yet.

Hope you get the idea.

In therouting documentation, there is a section how to pass data to controller.

In the controller docs, https://getkirby.com/docs/developer-guide/advanced/controllers#arguments-from-the-router, it tells you how to fetch this data.

The workflow is a little confusing for me.

  1. The user hits the domain. It goes into the router. Which I store in /config.php
  2. (:any) stores as $uid.
  3. This will go back to the advisor template which will hit site.php controller.
  4. In the controller then I specify if $uid is not Null. Then return a different template then this one.

Also, when returning the template. How to pass those variables into the template from the controller. We had this issue before where the system can’t pass variables from the controller into the template?

Why should it go back too the advisor template. What I’m suggesting is to return the find page. The controller for the findpage get the $uid and based on that value, returns one or the other snippet in the template.

what if somebody hits the domain directory.

/advisors/$id.

Passing the $uid would work if I hit the find page first. But what about if I hit the domain directly.

c::set('routes', array(
  array(
    'pattern' => 'advisor/(:any)',
    'action'  => function($any() {

if ($any == 'find') {
return 'template.php'; 
}

else {
return 'catchall.php '; 
}
    
    }
  )
));```

How to do something like this.

What domain? What is $id in your example?

Yes, you can also return a template, but then you have to pass all the data to the template, including the site and kirby objects. And you have to pass all that down to all snippets, ie. the header, footer snippets etc.

See the documentation for tpl::load()and examples here on the forum

andovo.test/advisor/find

or

$agent = $wildcard;

andavo.test/advisor/$agent

if ($domain == andovo.test/advisor/find) {

return find.php template.

}

else {
wildcard template.
}

What is ‘action’ => function($uid)

is $uid representing :any?

Thanks

yes, exactly.

An alternative could be to create a single blueprint page for the agents that you return with the agent name as data whenever an agent URL is called.

I used this and it redirects to the page I want. So I can manipulate from there. However. I can pull the url off the domain. But if I can parse it in the router and get the value from there. That would be cool. However, when I try and use the $data in the template. It doesn’t work.


c::set('routes', array(
    array(
        'pattern' => 'advisor/(:any)',
        'action' => function($uid) {
            $data = array(
                'kirby' => kirby(),
                'site'  => site(),
                'pages' => site()->children(),
                'page' => page($uid),
            );
            echo tpl::load(kirby()->roots()->templates() . DS . 'details.php', $data, true);
        }
    )));

When I try to do a print_r($data) in that template.

It returns.

an error.

Whoops \ Exception \ ErrorException (E_NOTICE)
Undefined variable: data

In your template, you will not have access to $data in this case, but to $site, $kirby, $pagesand$page, but$pageis not a page in your case, because the page doesn't exist (at least not if(:any)` is an agent.

I can do echo kirby()->request()->path()->nth(1);

Then from there. I can get my endpoint or pass the find page.