Escape template
public static escapeTemplate ( string $template ) : string | ||
$template | string | handlebars template string |
return | string | Escaped template |
/** * Read partial file content as string and store in context * * @param array<string,array|string|integer> $context Current context of compiler progress. * @param string $name partial name * * @return string|null $code compiled PHP code when success */ public static function read(&$context, $name) { $context['usedFeature']['partial']++; if (isset($context['usedPartial'][$name])) { return; } $cnt = static::resolve($context, $name); if ($cnt !== null) { $context['usedPartial'][$name] = SafeString::escapeTemplate($cnt); return static::compileDynamic($context, $name); } if (!$context['flags']['skippartial']) { $context['error'][] = "Can not find partial for '{$name}', you should provide partials or partialresolver in options"; } }
/** * Compile handlebars template into PHP code. * * @param string $template handlebars template string * @param array<string,array|string|integer> $options LightnCandy compile time and run time options, default is array('flags' => LightnCandy::FLAG_BESTPERFORMANCE) * * @return string|false Compiled PHP code when successed. If error happened and compile failed, return false. */ public static function compile($template, $options = array('flags' => self::FLAG_BESTPERFORMANCE)) { $context = Context::create($options); if (static::handleError($context)) { return false; } $code = Compiler::compileTemplate($context, SafeString::escapeTemplate($template)); static::$lastParsed = Compiler::$lastParsed; // return false when fatal error if (static::handleError($context)) { return false; } // Or, return full PHP render codes as string return Compiler::composePHPRender($context, $code); }