is there an issue with having a jstpl template and a php.view template with the same name?
Posted: 03 March 2021, 20:42
Just as the topic says, I'm using PHP to build the board at page load, but it doesn't seem to be firing again when I add a new element after the page is done (at least my self::dumps aren't showing up in the logs), so I'm trying to build the element temporarily in Javascript.
my php template:
php placement
Javascript template:
Javascript placement:
And here's how the JAVASCRIPT element appears in the html. (piece_4_1 was generated by the php at page load, piece 3_1 was just placed in JS)
It looks like it's trying to replicate the PHP formatting when it shouldn't be (and I also don't know where the dollar signs are coming from). Feels like it's trying to spit out a php variable (ie $top) into javascript (where $ is just a character and top is the variable), but I can't figure out why or where it would do that (other than what I'm trying to do being a no no) and I don't see it in the documentation anywhere.
my php template:
Code: Select all
<!-- BEGIN piece -->
<div id="piece_{X}_{Y}" class="piece piece_{KIND}_{COLOR}_{SIDE}" style="left: {LEFT}px; top: {TOP}"></div>
<!-- END piece -->Code: Select all
$this_player_id = $g_user->get_id();
$actual_x = ( $this_player_place == 1 ? $tile['x'] : 7-$tile['x'] );
$actual_y = ( $this_player_place == 1 ? $tile['y'] : 7-$tile['y'] );
$top = '';
$top = round( ($actual_y-1)*101+2 ) . "px; ";
if ($tile['color'] != $players[$this_player_id]['color']) {$top = $top . ' transform: rotate(180deg); ';}
self::dump("top after if: ", $top);
$this->page->insert_block( "piece", array(
'X' => $actual_x,
'Y' => $actual_y,
'LEFT' => round( ($actual_x-1)*101+2 ),
'TOP' => $top,
'KIND' => $tile['kind'],
'COLOR' => $tile['color'],
'SIDE' => $tile['side'],
'OWNER' => $this_player_idCode: Select all
var jstpl_piece='<div id="piece_${x}_${y}" class="piece piece_${kind}_${color}_${side}" style="left: ${LEFT} top: ${TOP} "></div>';Code: Select all
thisx = Number(((x-1)*101)+2);
thisx = thisx + "px; ";
thisy = Number(((y-1)*101)+2);
thisy = thisy + "px; ";
dojo.place( this.format_block( 'jstpl_piece', {
kind: kind,
color: color,
side: side,
left: thisx,
top: thisy,
x: x,
y: y
} ) , 'pieces' );And here's how the JAVASCRIPT element appears in the html. (piece_4_1 was generated by the php at page load, piece 3_1 was just placed in JS)
Code: Select all
<div id="piece_4_1" class="piece piece_footman_light_A" style="left: 305px; top: 2px; transform: rotate(180deg); "></div>
<div id="pieces">
<div id="piece_3_1" class="piece piece_duke_dark_A" style="left: $305 top: $2px; transform: rotate(180deg); "></div>
</div>