# Unexpected template render behaviour

**URL:** <https://casparcgforum.org/t/unexpected-template-render-behaviour/5717>\
**Category:** General\
**Tags:** template, html, server\
**Created:** [May 2, 2023, 10:44am UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717 "2023-05-02T10:44:54Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrea](https://casparcgforum.org/user_avatar/casparcgforum.org/andrea/32/775_2.png) [@Andrea](https://casparcgforum.org/u/Andrea)\
**Post date:** [May 2, 2023, 10:44am UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717/1 "2023-05-02T10:44:54Z")

</div>

I was trying to make a simple image composition to generate a gallery for social media, so I could process a lot of pictures automatically with a combination of “add” template and “snapshot”.  
So the template is very simple and has no animation, just text “div”, svg images and a png picture of the subject with the background cutted away (just 400x480px).

The client will send the “update” command with the new values and a function is called to make the changes, very simple and straight forward.

The strange thing that I encounter is that quite often doesn’t render everything, sometimes the image and texts are missing, sometimes just the texts are missing, sometimes the image is rendered in half.

 ![merged](https://casparcgforum.org/uploads/default/original/2X/a/a652790157986d36b08445362a7890879876466d.png)

```auto
function main() {

    Rider_FirstName_Field.innerHTML = Input_First_Name;
    Rider_LastName_Field.innerHTML = Input_Last_Name;
    Rider_Nationality_Field.innerHTML = Input_Nationality;

    if (Input_Last_Name.length > 0) {
        Rider_Face_Image.src = "../../_Images/Face/" + Input_Last_Name + "_" + Input_First_Name + ".png";;
        Rider_Face_Image.style.opacity = 1;
    } else {
        Rider_Face_Image.src = "";
        Rider_Face_Image.style.opacity = 0;
    }
    if (Input_Nationality.length > 0) {
        Rider_Flag_Image.src = "../../_Images/Flag/" + Input_Nationality + ".svg";;
        Rider_Flag_Image.style.opacity = 1;
    } else {
        Rider_Flag_Image.src = "";
        Rider_Flag_Image.style.opacity = 0;
    }
}

```

I’m not sure if that is normal or not, or if I’m doing something wrong in how I handle things.  
I found a simple solution which is to call the function more than once with a setInterval, it is just for postproduction in this case so I don’t care that much, but I would like to know more about it.

The important I think, is that it is not a flaw or a bug in the server code

---

<div class="post-metadata">

**Author:** ![Julusian](https://casparcgforum.org/user_avatar/casparcgforum.org/julusian/32/12_2.png) [@Julusian](https://casparcgforum.org/u/Julusian)\
**Post date:** [May 2, 2023, 10:56am UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717/2 "2023-05-02T10:56:38Z")

</div>

If you are using a recent build of master, this could be another case of [Consumer shows countdown clock \*skipping\* times in the output · Issue #1441 · CasparCG/server · GitHub](https://github.com/CasparCG/server/issues/1441)

---

<div class="post-metadata">

**Author:** ![Andrea](https://casparcgforum.org/user_avatar/casparcgforum.org/andrea/32/775_2.png) [@Andrea](https://casparcgforum.org/u/Andrea)\
**Post date:** [May 2, 2023, 11:13am UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717/3 "2023-05-02T11:13:36Z")

</div>

Ops, sorry, I forgot the server version

I’m using the 2.3.3 LTE on windows 11 with an Nvidia card  
in the log is shown as:

Server 2.3.2 fd75dd58 Dev

---

<div class="post-metadata">

**Author:** ![Julusian](https://casparcgforum.org/user_avatar/casparcgforum.org/julusian/32/12_2.png) [@Julusian](https://casparcgforum.org/u/Julusian)\
**Post date:** [May 2, 2023, 11:25am UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717/4 "2023-05-02T11:25:54Z")

</div>

Ok, it won’t be that bug then. I don’t know what will be at fault

---

<div class="post-metadata">

**Author:** ![Andrea](https://casparcgforum.org/user_avatar/casparcgforum.org/andrea/32/775_2.png) [@Andrea](https://casparcgforum.org/u/Andrea)\
**Post date:** [May 2, 2023, 11:39am UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717/5 "2023-05-02T11:39:52Z")

</div>

doesn’t looks to be a big problem, I think I never encountered it because animations probably have the same effect of recalling the function as I do in this case.

Let me know if you want me to do some tests or else, I will be happy to do that

---

<div class="post-metadata">

**Author:** ![noumaan](https://casparcgforum.org/letter_avatar_proxy/v4/letter/n/dfb087/32.png) [@noumaan](https://casparcgforum.org/u/noumaan)\
**Post date:** [May 13, 2023, 3:48am UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717/6 "2023-05-13T03:48:17Z")

</div>

Try remote debugging to diagnose the problem. It might help to understand what is going on.

---

<div class="post-metadata">

**Author:** ![Andrea](https://casparcgforum.org/user_avatar/casparcgforum.org/andrea/32/775_2.png) [@Andrea](https://casparcgforum.org/u/Andrea)\
**Post date:** [May 14, 2023, 6:39pm UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717/7 "2023-05-14T18:39:00Z")

</div>

I never tried remote debugging, I’m not sure how it works, but sounds good

---

<div class="post-metadata">

**Author:** ![andyw](https://casparcgforum.org/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@andyw](https://casparcgforum.org/u/andyw)\
**Post date:** [May 15, 2023, 10:11am UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717/8 "2023-05-15T10:11:07Z")

</div>

Remote debugging uses an instance of Chrome browser running on the CasparCG server to access the embedded chromium that is running a template on the server.

The CasparCG server needs the remote debug feature enabled as part of the server configuration. This is implemented in the \<html\> tag. For example to enable port 8081 for remote debug:

```auto
<html>
     <remote-debugging-port>8081</remote-debugging-port>
</html>

```

Other items such as \<enable-gpu\> may also be in the tag group.

Run a template on the CasparCG server.

Open an instance of Chrome on the server. In the address bar enter **chrome://inspect/#devices**

On the displayed page, tick the “Discover network targets” box, and click the Configure… button. Enter the address 127.0.0.1:8081 (or whichever port number you placed in the CasparCG config file). Click the Done button on the Target discovery settings.

After a few seconds you see a list of templates running on the server, including the template name and url. Click the blue “inspect” text to show the chrome dev tools page for the CasparCG template.

There is a small icon on the tools menu that looks like a small box at the bottom left of a larger box. This enables or disables the screencast mode. When screencast is enabled you see the output of the CasparCG template on the chrome page.

You can use the other tools to show the code, profile performance data, inspect the values of variables, and enter commands in the console panel. Commands include all standard Caspar invoked functions such as next(), update(), play() and stop(). For example if the template javascript code is accepts JSON wrapped data you can update a field named f0 using the console command:

```auto
update("{\"f0\":\"New text for f0\"}")

```

Or to avoid escaping quote marks inside quote marks use the single quote on the outer wrapper

```auto
update('{"f0":"New text for f0"}')

```

Of course when you run stop() the remote debug also closes.

---

<div class="post-metadata">

**Author:** ![Andrea](https://casparcgforum.org/user_avatar/casparcgforum.org/andrea/32/775_2.png) [@Andrea](https://casparcgforum.org/u/Andrea)\
**Post date:** [May 16, 2023, 12:03pm UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717/9 "2023-05-16T12:03:18Z")

</div>

Thank you very much for the guide, very interesting tool!

so, I tried with the photo gallery template, and seems to not detect anything. Also, even when on the server the template was incompletely rendered, on the remote debugging was all well rendered.

The good news is that on the latest server master there is no issue.  
Server 2.3.3 3e80053 Dev  
I tried a lot of times and managed to render everything fine all the times

---

<div class="post-metadata">

**Author:** ![andyw](https://casparcgforum.org/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@andyw](https://casparcgforum.org/u/andyw)\
**Post date:** [May 17, 2023, 12:21pm UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717/10 "2023-05-17T12:21:10Z")

</div>

Pleased to hear you have found a workable solution. There may be some diagnostic info in the screencast in remote debug operating, but the output not updating. Julusian has noted several times in the forum and the github server issues that the embedded chromium can be very tricky to connect into Caspar.

---

<div class="post-metadata">

**Author:** ![fdeigiudici](https://casparcgforum.org/user_avatar/casparcgforum.org/fdeigiudici/32/410_2.png) [@fdeigiudici](https://casparcgforum.org/u/fdeigiudici)\
**Post date:** [May 21, 2023, 8:09pm UTC](https://casparcgforum.org/t/unexpected-template-render-behaviour/5717/11 "2023-05-21T20:09:24Z")

</div>

this is great @andyw thanks!
