Smarty : {capture} to put code in your header page

If you are using Smarty to generate your templates, I strongly advice you to take advantage of the function: {capture}

This function is used to collect the output of the template between the tags {capture}{/capture} into a variable instead of displaying it.

Exemple  :

index.tpl

{capture name=header}
{literal}
<script type="text/javascript">
alert('Javascript in head');
</script>
{/literal}
{/capture}
<!-- Include Page Header using Smarty {include} -->
{include file="header.tpl"}
My index page content

header.tpl

<html>
<head>
<title>Page ttle</title>
{$smarty.capture.header}
</head>

Nb : “Javascript code” must be placed between {literal}{/literal}