Loading a row template for dynamic tabular input

If you have this form (for example) :

<?php $form = ActiveForm::begin(); ?>


    <?php foreach($models as $model): ?>

        <!-- row template -->


            <td><?= $form->field($model, 'firstName'); ?></td>

            <td><?= $form->field($model, 'lastName'); ?></td>


        <!-- // row template -->

    <?php endforeach; ?>


<?php ActiveForm::end(); ?>

Now, what is the best way that you’d use to get a copy of the code (template) between &#60;&#33;-- row template --&#62; and &#60;&#33;-- // row template --&#62;, so you can use it to add new rows dynamically using JavaScript?

Currently working on the same issue.

There are solutions but you have always to make a compromise somewhere.

Take a look at: