3

In my_module.routing.yml

my_module.detail:
  path: '/module/{id}'
  defaults:
    _controller: '\Drupal\module\Controller\DetailController::view'
  requirements:
    _access: 'TRUE'

In template twig file I'm calling via

<a href="{{ path('my_module.detail', {'id': item.id }) }}">Test</a>

Here my Id is not Integer It consists of string like AzT13AAa

So when I access it gives error like

Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "id" for route "my_module.detail" must match "[^/]++" ("" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 202 of core/lib/Drupal/Core/Routing/UrlGenerator.php).

  • Does item.id produce a value? The error sounds like it isn’t. – Kevin Apr 17 '18 at 3:43
  • 1
    Yes, is item a content entity? Then twig might confuse it with the id field object ,which is not a value. Try item.id() in that case, try prining item.id in your template to see what it is – Berdir Apr 17 '18 at 6:08
  • Ok let me check for value – Julia Apr 17 '18 at 6:15

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.