> For the complete documentation index, see [llms.txt](https://docs.mindstellar.com/osclass-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mindstellar.com/osclass-docs/v3.9.0/developers/plugins-themes/routes.md).

# Routes

### What are the routes for?

You could extend Osclass with plugins, and sometimes you need to create a special page, for example to show more options to your users.&#x20;

In previous versions, the url will look like:&#x20;

`domain.tld/index.php?page=custom&file=your_plugin/page.php`&#x20;

Which isn't the prettiest url you could see, and also the file path are visible which is not a problem, but it's not good. In 3.2 we added "routes" that will transform that ugly url into a more beauty one, like:&#x20;

`domain.tld/your_plugin_page` &#x20;

They even works with regular expressions to accept variables on the url.

### The route functions

To make routes works, we first need to create them:

```php
/**
* $id - Shortname of the route
* $regexp - Regular expression of the url
* $url - Required to be able to create the nice-looking url
* $file - file that will be loaded
*/
osc_add_route($id, $regexp, $url, $file)

Later we just need to get the url:
```

Later we just need to get the url:

```php
/**
* $id - Shortname of the previously created route
* $args - Optional, only required if your url accept parameters
*/
//For public routes
osc_route_url($id, [$args])

//For routes in the admin panel
osc_route_admin_url($id, [$args])
```

### Examples

Here is an example

```php
// Create route
osc_add_route(
     'dynamic-route',
     'dynamic-route/([0-9]+)/(.+)',
     'dynamic-route/{my-numeric-param}/{my-own-param}',
     osc_plugin_folder(__FILE__).'mydynamicroute.php'
   );
// Show link to it
echo osc_route_url(
         'dynamic-route', 
         array(
               'my-numeric-param' => '12345', 
               'my-own-param' => 
               'my-own-value'
               )
    );
```

### Notes

* Parameters in the $url should be enclosed between "{" and "}", example "{parameter}"
* Parameters should have the same name (case sensitive) in both, osc\_add\_route and osc\_route\_url
* Additionally, any file located in a folder called "admin" will be opened in admin panel, but show a 404 error in the public site

{% hint style="danger" %}
Remember that regular expressions could be tricky, make them truly unique so they will not collide with any other rule.
{% endhint %}

### Example plugin

An example plugin could be found in github : <https://github.com/osclass/osclass-plugins/tree/routes_example>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mindstellar.com/osclass-docs/v3.9.0/developers/plugins-themes/routes.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
