I have a hard time to style a link via the Drupal 8 render structure. This link needs to be displayed in my custom module:
$add_link = \Drupal::l('<i class="fa fa-cog"></i>' . t('Add new project'), $url);
So between de tags I want a Font awesome icon in front of the text. But Drupal print all html out as readable text.
I also notice that the l() function is deprecated in Drupal 8. So what is the best way to do this in the Drupal 8 render structure?
HTML Page with Drupal regions is like any other content. You add the HTML content and it will be rendered in the content region of the theme. To add new HTML Page, go to '`/html-page/html_page`'. You can also get here by clicking on Structure from the Admin toolbar.
This is a sandbox project, which contains experimental code for developer use only. Provides an additional formatter for the core Link field type in order to define a consistent link title using Manage Display. Options include: Use the field label as the link text.
Add links inside a t() method. If you want to add a link inside the t() you can do what Drupal suggests on Dynamic or static links and HTML in translatable strings: use Drupal\Core\Url; $url = Url::fromRoute('entity.
If, like me, you wanted to use a render array of #type => 'link'
and include an icon with it then you can do the following:
<?php
use Drupal\Core\Render\Markup;
use Drupal\Core\Url;
$form['actions']['reset_password'] = [
'#type' => 'link',
'#title' => Markup::create('<span class="glyphicon glyphicon-cog"></span> Forgot / Reset Password'),
'#url' => Url::fromRoute('user.pass'),
];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With