true, 'is_safe' => ['html', 'html_attrs'] ]), ]; } /** * Print `value` inside a template, or, if $value is empty, * print $message. * * The template can be customized. The template is a full path to another * template, or one of the key belows: * * - 'default' ; * - 'blockquote' ; * * `DateTimeInterface are also rendered. The date and time format may be set * using those key in `$options“ parameter: * * - `date_format` (default to `'medium'`) * - `time_format` (default to `'none'`) * * @param Environment $twig * @param string $value Default to 'No value'. Fallback to default if null * @param string $message * @param string $template * @param array $options * @return string */ public function printOrMessage( Environment $twig, $value, $message = 'No value', $template = 'default', array $options = [] ) { if ($value instanceof \DateTimeInterface) { $options = \array_merge([ 'date_format' => 'medium', 'time_format' => 'none' ], $options); switch ($template) { case 'default': case 'blockquote': $t = '@ChillMain/Extensions/PrintOrMessage/'.$template.'_date.html.twig'; break; default: $t = $template; } } else { switch ($template) { case 'default': case 'blockquote': $t = '@ChillMain/Extensions/PrintOrMessage/'.$template.'.html.twig'; break; default: $t = $template; } } return $twig->render($t, \array_merge([ 'value' => $value, 'message' => $message ?? 'No value' ], $options)); } }