I wasn't very clear about what I was trying to do. Basically I'm trying to replicate the ASP.NET MVC functionality where I can define a section at the bottom of my layout like this:
@Html.RenderSection( "scripts" );
Then I can add a script in my view like this, and it will be included at the bottom of the page instead of linked as a separate file:
@section scripts {
<script>
console.log('foobar');
</script>
}
I've managed to get similar functionality in Phalcon by including this at the bottom of my layout:
foreach ($scripts as $script) {
echo $script;
}
Then in my view I can add a script like this:
$scripts[] = "
<script>
console.log('foobar');
</script>
";
I believe I can achieve this with Volt blocks, but is there a better way without Volt?