in this tuto, I'll show you how to create a custom page at /custom-page-with-arguments/% that displays content based on arguments.
Example
mymodule.routing.yml
mymodule.custom-page-with-arguments:
path: '/custom-page-with-arguments/{name}'
defaults:
_controller: '\Drupal\mymodule\Controller\HelloController::index'
_title: 'custom page with arguments'
name: 'Codimth'
requirements:
_permission: 'access content'
default value of name is 'Codimth'.
src/Controller/HelloController.php
<?php
namespace Drupal\mymodule\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Class HelloController.
** @package Drupal\mymodule\Controller
*/
class HelloController extends ControllerBase
{
/**
* @param $name
* @return array
*/
public function index($name)
{
return [
'#type' => 'markup',
'#markup' => $this->t('Hello @name .', array('@name' => $name)),
];
}
}