I have the following code:

 return array(
      '#type' => 'markup',
      '#markup' => '<gcse:search queryParameterName="query" resultsUrl="'
        . Url::fromRoute('cn.search', [], ['absolute' => TRUE])->toString()
        . '"></gcse:search>',
      '#allowed_tags' => ['gcse', 'gcse:search'],

but the output is:

  <gcse search queryparametername="query" resultsurl="http://d8.constitutionnet.org/search2"></gcse>

How do I prevent the colon being converted to a space?

1 Answer 1


Use an inline template:

  return [
    '#type' => 'inline_template',
    '#template' => '<gcse:search queryParameterName="query" resultsUrl="{{ url }}"></gcse:search>',
    '#context' => [
      'url' => Url::fromRoute('cn.search', [], ['absolute' => TRUE]),
  • Thanks @4k4, but is the fact that '#allowed_tags' => ['gcse', 'gcse:search'] doesn't work a bug?
    – Nic
    Commented Oct 1, 2016 at 14:27
  • 1
    #allowed_tags is more for simple tags. If you put such complex html in a template or at least in an inline template, your module is also nice to themers, because they are able to change the template and/or the variables separately.
    – 4uk4
    Commented Oct 1, 2016 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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