How to render a link in drupal 8?

Public

How to render a link in drupal 8?

</> CopyGet raw version
php
  1. How to render a link ?
  2. $url = Url::fromRoute('modaltest.page');
  3. $internal_link = \Drupal::l(t('Modal Page'), $url);
  4.  
  5. // Other examples
  6. $internal_link = \Drupal::l(t('Modal Page'), Url::fromRoute('modaltest.page'));
  7.  
  8. // Return an link.
  9. return array('#markup' => \Drupal::l(t('Modal Page'), Url::fromRoute('modaltest.page')));