PHPackages                             craftsnippets/craft-named-routes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. craftsnippets/craft-named-routes

ActiveCraft-plugin[Utility &amp; Helpers](/categories/utility)

craftsnippets/craft-named-routes
================================

Named routes plugin for Craft CMS

3.1.0(1y ago)72.1k1[2 issues](https://github.com/craft-snippets/craft-named-routes/issues)[1 PRs](https://github.com/craft-snippets/craft-named-routes/pulls)MITPHP

Since Jun 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/craft-snippets/craft-named-routes)[ Packagist](https://packagist.org/packages/craftsnippets/craft-named-routes)[ RSS](/packages/craftsnippets-craft-named-routes/feed)WikiDiscussions craft5 Synced yesterday

READMEChangelog (9)Dependencies (1)Versions (11)Used By (0)

Named routes plugin for Craft CMS 5.x
=====================================

[](#named-routes-plugin-for-craft-cms-5x)

Installation
------------

[](#installation)

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

    ```
     cd /path/to/project

    ```
2. Then tell Composer to load the plugin:

    ```
     composer require craftsnippets/craft-named-routes

    ```
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Craft named routes.

Usage
-----

[](#usage)

This plugin allows you to get a URL of routes set in `config/routes.php` from within Twig templates - you will no longer need to hardcode routes structure in your markup.

In order to use the plugin, you will need to give your route an additional `name` attribute. Here is an example of a route that creates a user profile page:

```
'users/' => ['template' => 'pages/user', 'name' => 'userRoute'],

```

As you can see, we gave route name `userRoute`. To get URL of route in Twig template, you need to use `craft.namedRoutes.getUrl` function. Pass it route name and array or route tokens:

```
{{craft.namedRoutes.getUrl('userRoute', {
	user_id: 11,
}) }}

```

This will output URL looking like "".

Here are the parameters received by `craft.namedRoutes.getUrl` function:

- route name
- array of route tokens (optional - routes can have no tokens)
- optional parameter deciding if the token value should be checked by regexp rule, if such rule is provided within route token. Default: `true`.

You can also get *URI* instead or *URL* by using `getUri()` method:

```
{{craft.namedRoutes.getUri('userRoute', {
	user_id: 11,
}) }}

```

This will return URI "users/11".

Regexp rules of tokens
----------------------

[](#regexp-rules-of-tokens)

The last parameter of the function requires a bit of explanation. If route token has regexp rule provided (like `` - which would only accept digits), the plugin by default will throw an exception if the provided token value does not match this rule. This behavior can be overwritten by setting the third parameter of the function to `false`.

One of the use cases for this can be providing URL for [redirectInput](https://docs.craftcms.com/v3/dev/functions.html#redirectinput) when [adding entry from frontend](https://docs.craftcms.com/v3/dev/examples/entry-form.html), and our entry uses custom route. Poperties of the new entry can be used in `redirectInput` - for example, this URL will have `{id}` replaced with ID of added entry:

```
{{redirectInput('http://website.com/some-entry/{id}')}}

```

So, if our route looks like this:

```
'some-entry/' => ['template' => 'pages/entry', 'name' => 'entryRoute'],

```

Passing `{id}` as `entry_id` token value will cause an error, because string `{id}` does not matches `\d+` rule which accepts only digits. That's why you need to set the third parameter of a function to `false` in such a situation.

```
{{redirectInput(craft.namedRoutes.getUrl('entryRoute', {
	entry_id: '{id}',
}, false) )}}

```

Craft CMS routing documentation
-------------------------------

[](#craft-cms-routing-documentation)

More information about routes can be found in Craft [documentation](https://docs.craftcms.com/v3/routing.html#advanced-routing-with-url-rules).

Disclaimer
----------

[](#disclaimer)

Brought to you by [Piotr Pogorzelski](http://craftsnippets.com/)

Plugin icon made by [Law Xin Yi](https://iconscout.com/free-icon/road-sign-6496887).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~205 days

Recently: every ~375 days

Total

9

Last Release

567d ago

Major Versions

1.0.5 → 2.0.02022-06-10

2.0.1 → 3.0.02024-07-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/42622545?v=4)[Piotr Pogorzelski](/maintainers/piotrpog)[@piotrpog](https://github.com/piotrpog)

---

Top Contributors

[![piotrpog](https://avatars.githubusercontent.com/u/42622545?v=4)](https://github.com/piotrpog "piotrpog (13 commits)")

---

Tags

routesroutingcmsCraftcraftcmscraft-plugincraft named routes

### Embed Badge

![Health badge](/badges/craftsnippets-craft-named-routes/health.svg)

```
[![Health](https://phpackages.com/badges/craftsnippets-craft-named-routes/health.svg)](https://phpackages.com/packages/craftsnippets-craft-named-routes)
```

###  Alternatives

[verbb/formie

The most user-friendly forms plugin for Craft.

102393.6k70](/packages/verbb-formie)[verbb/comments

Add comments to your site.

13753.9k](/packages/verbb-comments)[verbb/navigation

Create navigation menus for your site.

92705.0k18](/packages/verbb-navigation)[verbb/vizy

A flexible visual editor field for Craft.

4250.4k](/packages/verbb-vizy)[verbb/hyper

A user-friendly links field for Craft.

24147.8k12](/packages/verbb-hyper)[verbb/workflow

Enforce multi-step review processes for creating entries.

138124.2k1](/packages/verbb-workflow)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
