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

Riadh Rahmi

Senior Web Developer (Drupal & Laravel)

I am a senior web developer, I have experience in planning and developing large scale dynamic web applications especially in Drupal and Laravel.

Web Posts

Search

Page Facebook