to keep things simple, I am trying to load a specific set of values from a database, which using the following code works:

foreach ( database::load() as $bdt) {
  $row[] = (array) $bdt;

$content['table'] = array(
  '#type' => 'table',
  '#rows' => $row,
  '#empty' => t('No entries available.'),

Which produces the following:

                  <td>5.00 PM</td>
                  <td>1:00 PM</td>
                  <td>1:00 PM</td>
                  <td>3:00 PM</td>
                  <td>3:00 PM</td>
                  <td>5:00 PM</td>

But I don't want to use table formats and I want to use other html markup tags, such as "<p>" or "<div>". I have tried to change the '#type' => 'table' to '#markup' but it will not render anything.

$content['table'] = array('#markup => '<p><span class="blue">time</span> ' . $row '</p>',);

I have searched a few sites about it, but all point information back to using table format.

The working code was extracted from the "example modules" using the DBTNG example.

Please can anyone tell me how to go about it?

Many Thanks


As you do not like table.html.twig, I suggest to write your own table theme. As a reference, you can look how this is done for field_ui_table in core.

Or you use inline_template:

$content['table'] = [
   '#type' => 'inline_template',
   '#template' => '{%- for row_value in row -%}<p><span class="blue"> time </span>{{ row_value }}</p>{%- endfor -%}',
   '#context' => ['row' => $row],
  • Hi Maouna, I do use the same database values on the another page which uses the table format, I just need to modify the markup on another page, for other reasons. If you understand. – Jamie Jun 22 '16 at 10:53
  • That is ok. Then you do not exchange the template for tables in general, but write your own and use it only when needed. – Maouna Jun 22 '16 at 11:57
  • So, its not as simple as using a different array type, and I have to write up a new function. I've looked at the field_ui_table in core, and haven't got a clue what to do with that. Think I will go another route. Thanks Maouna – Jamie Jun 22 '16 at 12:52
  • Hi Maouna, thank you very much. You're a STAR. That is what I was looking for, and looks much more easier than having to write a new function/theme hook. Thanks – Jamie Jun 22 '16 at 19:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.