I am learning to make use of "Views within views" in Kohana PHP framework in order to write more modular code. The following code allows me to pass data dependencies to the partial view and then I can render them in a loop.
foreach ($datas as $data) {
$view = new View('partial');
$view->set('data', $data);
$view->render(TRUE);
}
My question is how do I include JS and CSS dependencies? Ideally I want to put them inside the 'partial' view file i.e. partial.php
partial.php
<link> ... </link>
<script> ... </script>
<div> ... </div>
But this is bad because if I render the partial view in a loop they would get included multiple times. Is there a way to do it with a Kohana helper function of sorts that allows me to append JS and CSS to the bottom of the page and also check for duplicates so if a file is already there, it will not include it again.
The reason I want to put this inside partial.php is so that other developers using the partial view will be able to easily re-use the code without looking for the JS and CSS dependencies.