Page 1 of 1

Passing data to tpl file

Posted: 28 January 2025, 15:52
by tony58uk
Hi all,

I'm having an issue I would like some help with please.

I'm trying to create custom player boards in the score area.

In the tpl file I have the following code

Code: Select all

const jstpl_player_board = (type) => '<div class="cp_board"> <div class="die dietype_${type}" id="cp_die_${id}"></div></div>';
and in the JS file I have this code

Code: Select all

this.getPlayerPanelElement(player.id).innerHTML = jstpl_player_board(player.god);
Data is not being passed into the tpl, it must be something simple I am missing?

Cheers

Re: Passing data to tpl file

Posted: 28 January 2025, 16:13
by thoun
Do you have errors in the console? Your template interpolates type and id, but only have type as a parameter. It should be (type, id) => and be called accordingly.

Re: Passing data to tpl file

Posted: 28 January 2025, 16:17
by tony58uk
I've changed it to this

Code: Select all

const jstpl_player_board = (type) => '<div class="cp_board"><div class="die dietype_${type}"></div></div>';
But it's still not passing data through.

When I inspect the element ${type} is there instead of the data I'm trying to pass. I'm missing something silly I know, but cannot find anything on the web.

Cheers

Re: Passing data to tpl file

Posted: 28 January 2025, 16:21
by thoun
Oh yes, you're using single quote (') instead of backticks (`) so it doesn't interpolate at all.

Re: Passing data to tpl file

Posted: 28 January 2025, 16:26
by tony58uk
OMG

Fixed, thanks. I knew it was something silly!!!!