Announcement

Collapse
No announcement yet.

Code Snippet in head tag

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Code Snippet in head tag

    Hello,

    I need to add a code snippet in the <head></head> tag of every page in espoCRM, frontend and portals etc. The code is just adding a simple tag like


    <call-us-selector phonesystem-url="{externalUrl}" party="{party}"></call-us-selector>
    <script defer src="{externalUrl}" id="{id}" charset="utf-8"></script>

    Alternatively, the above code snippet could be added above the <body> tag but I would like it to be loaded for every page. This creates a chatbox.

  • #2
    Hi, There's no way to customize the HTML page template. But you can utilize a javascript file that will insert the tags. https://docs.espocrm.com/development...nt/#scriptlist

    Comment


    • czcpf
      czcpf commented
      Editing a comment
      Thanks yuri.
      Last edited by czcpf; 08-18-2023, 10:48 PM.

  • #3
    Thanks, I must be missing something basic here because it isn't loading the javascript file.

    Espo/Modules/{MyModuleName}/Resources/metadata/app/client.json

    Code:
    {
        "scriptList": [
            "__APPEND__",
            "client/modules/{my-module-name}/lib/test.js"
        ],
        "cssList": [
        "__APPEND__",
        "client/modules/{my-module-name}/css/custom.css"
        ]
    }​
    client/modules/{my-module-name}/lib/test.js

    Code:
    console.log('test');
    I see it loads my custom.css in the <head></head> but it doesn't load test.js ? Nor does it show the output test in the console?



    Comment


    • #4
      For anyone else having this trouble, it wasn't loading because I am in developer mode. So I had to change client.json to:


      Code:
      {
          "scriptList": [
              "__APPEND__",
              "client/modules/{my-module-name}/lib/test.js"
          ],
          "developerModeScriptList": [
              "__APPEND__",
              "client/modules/{my-module-name}/lib/test.js"
          ],​
          "cssList": [
              "__APPEND__",
              "client/modules/{my-module-name}/css/custom.css"
              ]
      }​​
      which is odd because even in developer mode it still loaded the custom.css and there is another property here called developerModeCssList... Also, does anyone know how to indent code when pasting on this forum?





      Comment


      • #5
        It's documented (right below). There's nothing odd. This was not intended for cases like yours, but for including JS bundles or files. There's the need to have developer and non-developer sources separate as they are different (minimized bundles vs non-mininized sources).

        And there's no developerModeCssList.

        If you don't use json schema, I recommend start using. It's much easier to work with metadata.​

        Comment


        • czcpf
          czcpf commented
          Editing a comment
          I do use json schema when developing. I meant indenting code when we paste in this forum. It always removes the indentation.
      Working...
      X