I am making a theme for Drupal 7 that includes an HTML5/CSS3 animation in the header. The animation works fine, but I want to generate the HTML for it dynamically so there is an element of randomness.
At the moment I am doing this via a pair of simple for loops in page.tpl.php but I am aware this isn't really the best place to put the code. I have spent a little while searching and most answers seem to deal with modifying variables or code that Drupal puts out, whereas this is generating some completely new HTML.
What is the "Drupal way" to handle this? Just add a custom function to template.php that I call (themename_mycustomfunction) or do it in the preprocessor function (themename_preprocess_page) to add the generated HTML as a variable? Thanks
EDIT: This is the code I've currently got located at the top of my page.tpl.php. Nothing fancy, just generates some divs with the classes that the CSS3 animation will use. Where is the best place to put it though?
<div id="anim">
<?php
for ($i = 1; $i <= 10; $i++) {
?>
<div class="block o<?php print rand(1,3); ?> w<?php print rand(1,6); ?> x<?php print rand(1,9); ?> start"></div>
<?php
}
?>
<?php
for ($i = 1; $i <= 20; $i++) {
?>
<div class="block o<?php print rand(1,3); ?> w<?php print rand(1,6); ?> x<?php print rand(1,9); ?>"></div>
<?php
}
?>
</div>