1

I have a Comodo certificate for my site to serve content using HTTPS.

I would like to add the Comodo TrustLogo (https://trustlogo.com/) so that it appears on every content page. The problem is that the JavaScript comprises of two parts that must be placed in specific locations according to Comodo:

a) One piece must be loaded just before the HTML HEAD closing tag.

The generic code Comodo wants me to include is:

<script type="text/javascript"> //<![CDATA[ 
  var tlJsHost = ((window.location.protocol == "https:") ? "https://secure.comodo.com/" : "http://www.trustlogo.com/");
  document.write(unescape("%3Cscript src='" + tlJsHost + "trustlogo/javascript/trustlogo.js' type='text/javascript'%3E%3C/script%3E"));
  //]]>
</script>

b) The second piece must be included just before the HTML BODY closing tag.

The JavaScript is this - anonymised for site-specific content:

<script language="JavaScript" type="text/javascript">
  TrustLogo("https://www.example.com/path/to/image.png", "CL1", "none");
</script>
<a href="https://www.positivessl.com/" id="comodoTL">Positive SSL Wildcard</a>

Since Bartik and other themes do not meddle with the HTML page stuff (only with the actual content) I looked into messing with the file

core/modules/system/templates/html.html.twig

and add some content there, but stuff does not appear - it seems ignored as it doesn't even appear in the HTML source...

Please help!

Thanks, Michel

1 Answer 1

1

First of all, I hope you didn't edit any files in core :)
Secondly, you can of course add the custom scripts in the HTML twig file, but you need to add this template to you active theme and clear theme registry (or all) cache in order for the changes to appear.

Here is a complete html.html.twig file code:

{#
/**
 * @file
 * Default theme implementation for the basic structure of a single Drupal page.
 *
 * Variables:
 * - logged_in: A flag indicating if user is logged in.
 * - root_path: The root path of the current page (e.g., node, admin, user).
 * - node_type: The content type for the current node, if the page is a node.
 * - head_title: List of text elements that make up the head_title variable.
 *   May contain or more of the following:
 *   - title: The title of the page.
 *   - name: The name of the site.
 *   - slogan: The slogan of the site.
 * - page_top: Initial rendered markup. This should be printed before 'page'.
 * - page: The rendered page markup.
 * - page_bottom: Closing rendered markup. This variable should be printed after
 *   'page'.
 * - db_offline: A flag indicating if the database is offline.
 * - placeholder_token: The token for generating head, css, js and js-bottom
 *   placeholders.
 *
 * @see template_preprocess_html()
 *
 * @ingroup themeable
 */
#}
<!DOCTYPE html>
<html{{ html_attributes }}>
  <head>
    <head-placeholder token="{{ placeholder_token|raw }}">
    <title>{{ head_title|safe_join(' | ') }}</title>
    <css-placeholder token="{{ placeholder_token|raw }}">
    <js-placeholder token="{{ placeholder_token|raw }}">
    <script type="text/javascript"> //<![CDATA[ 
      var tlJsHost = ((window.location.protocol == "https:") ? "https://secure.comodo.com/" : "http://www.trustlogo.com/");
      document.write(unescape("%3Cscript src='" + tlJsHost + "trustlogo/javascript/trustlogo.js' type='text/javascript'%3E%3C/script%3E"));
      //]]>
    </script>
  </head>
  <body{{ attributes }}>
    {#
      Keyboard navigation/accessibility link to main content section in
      page.html.twig.
    #}
    <a href="#main-content" class="visually-hidden focusable">
      {{ 'Skip to main content'|t }}
    </a>
    {{ page_top }}
    {{ page }}
    {{ page_bottom }}
    <js-bottom-placeholder token="{{ placeholder_token|raw }}">
    <script language="JavaScript" type="text/javascript">
      TrustLogo("https://www.example.com/path/to/image.png", "CL1", "none");
    </script>
    <a href="https://www.positivessl.com/" id="comodoTL">Positive SSL Wildcard</a>
  </body>
</html>

You can put this file in your active theme /templates folder, clear cache and it'll load the logo on every page.
There are other ways to do so like using custom module to inject the code, but for simplicity, you can use this solution.

3
  • Hi Ismail, thanks for this, it works like a breeze! :) Indeed, a custom module would be interesting to look at since it would alleviate peeps from hacking code and templates. I would be interested in such a module, but currently do not have the time nor resources to do so myself...
    – MDr
    Commented Oct 10, 2016 at 8:07
  • Would this also work in Drupal 7?
    – Olegs
    Commented Feb 16, 2017 at 8:48
  • sorry for the late response, but yes it can be done in Drupal 7, simply edit the html.tpl.php in your theme Commented Apr 8, 2017 at 9:38

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.