Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

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)),
        ];
    }

}
Tags :

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon