You are here

public static function WebformTwigExtension::renderTwigTemplate in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Twig/WebformTwigExtension.php \Drupal\webform\Twig\WebformTwigExtension::renderTwigTemplate()

Render a Twig template with a webform submission.

Parameters

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

string $template: A inline Twig template.

array $options: (optional) Template and token options.

array $context: (optional) Context to be passed to inline Twig template.

Return value

string The fully rendered Twig template.

See also

\Drupal\webform\Element\WebformComputedTwig::computeValue

\Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::getMessage

4 calls to WebformTwigExtension::renderTwigTemplate()
EmailWebformHandler::getMessage in src/Plugin/WebformHandler/EmailWebformHandler.php
Get a fully populated email for a webform submission.
WebformAttachmentTwig::getFileContent in modules/webform_attachment/src/Element/WebformAttachmentTwig.php
Get a webform attachment's file content.
WebformComputedTwig::computeValue in src/Element/WebformComputedTwig.php
Compute value.
WebformElementBase::formatCustomItem in src/Plugin/WebformElementBase.php
Format an element's item using custom HTML or plain text.

File

src/Twig/WebformTwigExtension.php, line 249

Class

WebformTwigExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\webform\Twig

Code

public static function renderTwigTemplate(WebformSubmissionInterface $webform_submission, $template, array $options = [], array $context = []) {
  try {
    $build = static::buildTwigTemplate($webform_submission, $template, $options, $context);
    return \Drupal::service('renderer')
      ->renderPlain($build);
  } catch (\Exception $exception) {
    if ($webform_submission
      ->getWebform()
      ->access('update')) {
      \Drupal::messenger()
        ->addError($exception
        ->getMessage());
    }
    \Drupal::logger('webform')
      ->error($exception
      ->getMessage());
    return '';
  }
}