use Drupal\Component\Utility\Html; $link_url = 'http://example.com'; $image_src = 'http://example.com/image.png'; $link = Html::link( $link_url, Html::tag('img', '', ['src' => $image_src]), ['class' => 'image-link'] ); echo $link;
use Drupal\Component\Utility\Html; $data = [ ['John Doe', 'johndoe@example.com', '123-456-7890'], ['Jane Smith', 'janesmith@example.com', '987-654-3210'], ]; $table_rows = array_map(function ($row_data) { $row_cells = array_map(function ($cell_data) { return Html::tag('td', $cell_data); }, $row_data); return Html::tag('tr', implode('', $row_cells)); }, $data); $table = Html::tag('table', implode('', $table_rows)); echo $table;This code uses an array of data rows to generate an HTML table using the Html::tag() method. The array_map function is used to map the data rows to HTML table rows with table cells inside them. The resulting HTML code will be a table with two rows of data, each containing three cells.