Add option to prepend header/footer to existing content

This commit is contained in:
Kijin Sung 2025-02-17 20:09:51 +09:00
parent a66b036dd5
commit 7d8c09750b

View file

@ -2508,11 +2508,19 @@ class Context
* Add html code before </head>
*
* @param string $header add html code before </head>.
* @param bool $prepend
* @return void
*/
public static function addHtmlHeader($header)
public static function addHtmlHeader($header, bool $prepend = false)
{
self::$_instance->html_header .= (self::$_instance->html_header ? "\n" : '') . $header;
if ($prepend)
{
self::$_instance->html_header = $header . (self::$_instance->html_header ? "\n" : '') . self::$_instance->html_header;
}
else
{
self::$_instance->html_header .= (self::$_instance->html_header ? "\n" : '') . $header;
}
}
/**
@ -2594,10 +2602,19 @@ class Context
* Add html code after <body>
*
* @param string $header Add html code after <body>
* @param bool $prepend
* @return void
*/
public static function addBodyHeader($header)
public static function addBodyHeader($header, bool $prepend = false)
{
self::$_instance->body_header .= (self::$_instance->body_header ? "\n" : '') . $header;
if ($prepend)
{
self::$_instance->body_header = $header . (self::$_instance->body_header ? "\n" : '') . self::$_instance->body_header;
}
else
{
self::$_instance->body_header .= (self::$_instance->body_header ? "\n" : '') . $header;
}
}
/**
@ -2614,10 +2631,19 @@ class Context
* Add html code before </body>
*
* @param string $footer Add html code before </body>
* @param bool $prepend
* @return void
*/
public static function addHtmlFooter($footer)
public static function addHtmlFooter($footer, bool $prepend = false)
{
self::$_instance->html_footer .= (self::$_instance->html_footer ? "\n" : '') . $footer;
if ($prepend)
{
self::$_instance->html_footer = $footer . (self::$_instance->html_footer ? "\n" : '') . self::$_instance->html_footer;
}
else
{
self::$_instance->html_footer .= (self::$_instance->html_footer ? "\n" : '') . $footer;
}
}
/**