Currently I'm echoing html elements using php. Other times, I need to use javascript and create this elements dinamically (for example, some functions in mobile work differently and need some tweaks in the DOM). Unfortunately I'm spanning two different dimensions of elements (or more) in the code and need to update all of them if I want to change something. As an example:
Streaming long polling with javascript (jQuery):
...append("<div></div><div></div><div></div><div></div>");
PHP echo
echo "<div></div><div></div><div></div><div></div>";
Something other in php with for each echo
foreach(...){
echo "<div></div>";echo "<div></div>";
(...)
foreach(...){
echo "<div></div>";
echo "<div></div>"
}
}
If I want to change the structure of this element I would have to change ALL of the 3 situations, from 4 divs to 2 divs or 1 for example. How exactly could I centralize all this elements throughout php and javascript? I thought of having a string in php and spanning as templates to javascript but it gets messed up when making dynamic classes and other properties because of concatenation. Does anyone know of another way to do this?