drupal8 url link

来源:互联网 发布:快递单号记录软件 编辑:程序博客网 时间:2024/06/10 03:48
  1. // Internal path (defined by a route in Drupal 8).
  2. use Drupal\Core\Url;
  3. $url= Url::fromRoute('book.admin');
  4. $internal_link= \Drupal::l(t('Book admin'),$url);
  5.  
  6. // External Uri.
  7. use Drupal\Core\Url;
  8. $url= Url::fromUri('http://www.example.com/');
  9. $external_link= \Drupal::l(t('External link'),$url);
  10.  
  11. ==================================or==================================================
  12. use Drupal\Core\Url;
  13. use Drupal\Core\Link;
  14. $url= Url::fromRoute('entity.node.edit_form',array('node'=> NID));
  15. $project_link= Link::fromTextAndUrl(t('Open Project'),$url);
  16. $project_link= $project_link->toRenderable();
  17. // If you need some attributes.
  18. $project_link['#attributes']= array('class'=> array('button','button-action','button--primary','button--small'));

  1. print render($project_link);
https://chromatichq.com/blog/creating-links-within-twig-templates-using-path-and-url
// Link to the default frontpage content listing view:<a href="{{ path('view.frontpage') }}">{{ 'View all content'|t }}</a>// Link to a specific node page:<a href="{{ path('entity.node.canonical', {'node': node.id}) }}">{{ 'Read more'|t }}</a>// Link to a specific user profile page:<a href="{{ path('entity.user.canonical', {'user': user.id}) }}">{{ 'View user profile'|t }}</a>// Link to a view, and throw in some additional query string parameters:<a href="{{ path('view.articles.page_1', {'page': 2}) }}">{{ 'Go to page 2'|t }}</a>// Link to a view and pass in some arguments to the view:<a href="{{ path('view.recent_articles_by_author.page_1', {'arg_0': user.field_display_name.value|drupal_escape }) }}">{{ 'See all the articles written by'|t }} {{ user.field_display_name.value }}</a>

0 0
原创粉丝点击