本文整理汇总了PHP中Twig_Environment::render方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::render方法的具体用法?PHP Twig_Environment::render怎么用?PHP Twig_Environment::render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Environment
的用法示例。
在下文中一共展示了Twig_Environment::render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* {@inheritdoc}
*/
public function validate($emailTemplate, Constraint $constraint)
{
/** @var EmailTemplate $emailTemplate */
/** @var VariablesConstraint $constraint */
$fieldsToValidate = array('subject' => $emailTemplate->getSubject(), 'content' => $emailTemplate->getContent());
foreach ($emailTemplate->getTranslations() as $trans) {
if (in_array($trans->getField(), array('subject', 'content'))) {
$fieldsToValidate[$trans->getLocale() . '.' . $trans->getField()] = $trans->getContent();
}
}
$relatedEntity = false;
if (class_exists($emailTemplate->getEntityName())) {
$className = $emailTemplate->getEntityName();
$relatedEntity = new $className();
}
$errors = array();
foreach ($fieldsToValidate as $field => $value) {
try {
$this->twig->render($value, array('entity' => $relatedEntity, 'user' => $this->getUser()));
} catch (\Exception $e) {
$errors[$field] = true;
}
}
if (!empty($errors)) {
$this->context->addViolation($constraint->message);
}
}
示例2: execute
/**
* Execute Command
*
* @param InputInterface $input
* @param OutputInterface $output
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$email = $this->twig->render('test.twig');
$message = $this->mailer->createMessage()->setSubject('PHP RFC Digestor Test Email')->setFrom('notifier@php-rfc-digestor.com')->setTo($input->getArgument('email'))->setBody($email, 'text/html');
$this->mailer->send($message);
$output->writeln(sprintf('<info>Email sent to %s</info>', $input->getArgument('email')));
}
示例3: summernoteInit
/**
* @return string
*/
public function summernoteInit()
{
$template = $this->parameters['init_template'];
$options = [];
$options['fontname'] = count($this->parameters['fontname']) > 0 ? $this->prepareArrayParameter('fontname') : $this->getDefaultFontname();
$options['fontnocheck'] = count($this->parameters['fontnocheck'] > 0) ? $this->prepareArrayParameter('fontnocheck') : null;
$options['language'] = isset($this->parameters['language']) ? $this->parameters['language'] : null;
$options['plugins'] = isset($this->parameters['plugins']) ? $this->parameters['plugins'] : null;
$options['selector'] = $this->parameters['selector'];
$options['width'] = $this->parameters['width'];
$options['height'] = $this->parameters['height'];
$options['include_jquery'] = $this->parameters['include_jquery'];
$options['include_bootstrap'] = $this->parameters['include_bootstrap'];
$options['include_fontawesome'] = $this->parameters['include_fontawesome'];
$options['fontawesome_path'] = $this->parameters['fontawesome_path'];
$options['bootstrap_css_path'] = $this->parameters['bootstrap_css_path'];
$options['bootstrap_js_path'] = $this->parameters['bootstrap_js_path'];
$options['jquery_path'] = $this->parameters['jquery_path'];
$options['summernote_css_path'] = $this->parameters['summernote_css_path'];
$options['summernote_js_path'] = $this->parameters['summernote_js_path'];
$options['jquery_version'] = $this->parameters['jquery_version'];
$options['toolbar'] = $this->prepareToolbar();
$base_path = !isset($this->parameters['base_path']) ? 'bundles/fmsummernote/Jquery' . $options['jquery_version'] . '.x/' : $this->parameters['base_path'];
return $this->twig->render($template, ['sn' => $options, 'base_path' => $base_path]);
}
示例4: parse
public function parse($buffer, $context = array())
{
/** @var \Twig_Loader_Array $loader */
$loader = $this->twigEnvironment->getLoader();
$loader->setTemplate('__TEMPLATE__', $buffer);
return $this->twigEnvironment->render('__TEMPLATE__', $context);
}
示例5: run
/**
* @param Activity $activity
*
* @return Result
*/
public function run(Activity $activity)
{
$challenge = $activity->getChallengeObject();
$worker = $this->getWorker($challenge->getExecutionMode());
// 1) write all of the files (different for contexts)
// 2) call setupContext() (different for contexts)
// 3) call grade() and use results (different for contexts)
$filesToWrite = $this->getFilesToCreate($activity);
$initialExecutionResult = new CodingExecutionResult($filesToWrite);
// serialize this, so we can easily fetch the input files
$filesToWrite['executionResult.cache'] = serialize($initialExecutionResult);
// write the challenge class name
$filesToWrite['ChallengeClass.php'] = $activity->getChallengeClassContents();
// write our executor.php and execute that
$executionCode = $this->twig->render('code_executor.php.twig', array('workerClass' => get_class($worker), 'projectPath' => $this->projectRootDir, 'challengeFilename' => 'ChallengeClass.php', 'challengeClassName' => $activity->getChallengeClassName(), 'entryPointFilename' => $challenge->getFileBuilder()->getEntryPointFilename()));
$filesToWrite['execution.php'] = $executionCode;
$codeExecutor = new CodeExecutor($filesToWrite, 'execution.php');
$executionResult = $codeExecutor->executePhpProcess();
$result = new Result($activity);
// clean things up just in case - but the worker should take care of this
$result->setLanguageError(self::cleanError($executionResult->getLanguageError(), $executionResult->getCodeDirectory()));
$result->setGradingError($executionResult->getGradingError());
$result->setOutput($executionResult->getOutput());
return $result;
}
示例6: getLogs
public function getLogs($entity)
{
if (!is_object($entity)) {
return '';
}
return $this->twig->render($this->template, array('logEntities' => $this->logsFromEntity($entity)));
}
示例7: replace
public function replace($zpl, array $params = [])
{
if (empty($zpl)) {
return '';
}
return $this->twig->render($zpl, $params);
}
示例8: renderTwig
protected function renderTwig($template, $vars)
{
$vars['alerts'] = $this->getAlerts();
if (!empty($this->post)) {
$vars['post'] = $this->post;
} else {
if (!empty($_SESSION['post'])) {
$vars['post'] = $_SESSION['post'];
}
}
if (!empty($this->get)) {
$vars['get'] = $this->get;
} else {
if (!empty($_SESSION['get'])) {
$vars['get'] = $_SESSION['get'];
}
}
if (!empty($_SESSION['user'])) {
$vars['curUser'] = $_SESSION['user'];
}
echo $this->twig->render($template, $vars);
$this->resetAlerts();
unset($_SESSION['post']);
unset($_SESSION['get']);
}
示例9: fetch
/**
* @see IRenderEngine::fetch()
*/
function fetch($template)
{
if (strpos('.', $template) === false) {
$template .= '.html';
}
return $this->twig->render($template, $this->assignments);
}
示例10: renderFieldDisplay
/**
* @param \Twig_Environment $environment
* @param FieldableEntity $entity
* @param string $field
*
* @return string
* @internal param \Twig_Environment $environment
*/
public function renderFieldDisplay(\Twig_Environment $environment, FieldableEntity $entity, $field)
{
$class = get_class($entity);
$displayMapping = $this->displayManager->getEntityConfig($class);
$fieldSettings = $this->fieldManager->getEntityFieldMapping($class);
$html = '';
if ($displayMapping['options']['fields'][$field]) {
$displayFieldSettings = $displayMapping['options']['fields'][$field] + ['type' => null, 'label' => true, 'label_inline' => false, 'options' => []];
$display = $this->displayManager->getDisplayDefinition($displayFieldSettings['type']);
$fieldEntity = call_user_func([$entity, 'get' . $field]);
$fieldDisplayOptions = $displayFieldSettings['options'] ?: [];
$templateOptions = ['entity' => $fieldEntity, 'field_settings' => $fieldSettings, 'field_name' => $field, 'label' => is_string($displayFieldSettings['label']) ?: ($displayFieldSettings['label'] ? $field : false), 'label_inline' => $displayFieldSettings['label_inline']];
if ($fieldSettings[$field]['options']['limit'] > 1) {
$subHtml = '';
$subTemplateOptions = $templateOptions;
$subTemplateOptions['label'] = false;
foreach ($fieldEntity as $fieldEntityItem) {
$subHtml .= $environment->render($display->getTemplate(), $subTemplateOptions + $display->getTemplateOptions($fieldEntityItem, $fieldDisplayOptions));
}
$templateOptions['rows'] = $subHtml;
$html = $environment->render($display->getListTemplate(), $templateOptions + $display->getListTemplateOptions($fieldEntity, $fieldDisplayOptions));
} else {
$html = $environment->render($display->getTemplate(), $templateOptions + $display->getTemplateOptions($fieldEntity, $fieldDisplayOptions));
}
}
return $html;
}
示例11: process
/**
* {@inheritDoc}
*/
public function process($layoutSrc, Response $response, array $placeResponses)
{
if (!$this->twig->hasExtension('supraPage')) {
throw new \UnexpectedValueException('Missing for Supra Page extension.');
}
$response->setContent($this->twig->render($layoutSrc, array('responses' => $placeResponses)));
}
示例12: summernoteInit
/**
* @return string
*/
public function summernoteInit()
{
$template = $this->parameters['init_template'];
$options = [];
$options['language'] = isset($this->parameters['language']) ? $this->parameters['language'] : null;
$options['plugins'] = isset($this->parameters['plugins']) ? $this->parameters['plugins'] : null;
$options['selector'] = $this->parameters['selector'];
$options['width'] = $this->parameters['width'];
$options['height'] = $this->parameters['height'];
$options['include_jquery'] = $this->parameters['include_jquery'];
$options['include_bootstrap'] = $this->parameters['include_bootstrap'];
$options['include_fontawesome'] = $this->parameters['include_fontawesome'];
$options['fontawesome_path'] = $this->parameters['fontawesome_path'];
$options['bootstrap_css_path'] = $this->parameters['bootstrap_css_path'];
$options['bootstrap_js_path'] = $this->parameters['bootstrap_js_path'];
$options['jquery_path'] = $this->parameters['jquery_path'];
$options['summernote_css_path'] = $this->parameters['summernote_css_path'];
$options['summernote_js_path'] = $this->parameters['summernote_js_path'];
$options['upload_images'] = $this->parameters['upload_images'];
$options['image_upload_route'] = $this->parameters['image_upload_route'];
$options['max_upload_size'] = $this->parameters['max_upload_size'];
$options['toolbar'] = $this->prepareToolbar();
$basePath = !isset($this->parameters['base_path']) ? 'bundles/adnsummernote/' : $this->parameters['base_path'];
return $this->twig->render($template, ['sn' => $options, 'base_path' => $basePath]);
}
示例13: render
/**
* {@inheritdoc}
*/
public function render(array $context, $template = null)
{
if (null === $template) {
$template = $this->template;
}
return $this->twig->render($template, $context);
}
示例14: indexAction
public function indexAction(Request $request)
{
$response = new Response();
$response->setPrivate();
$response->setContent($this->twig->render('www/Index.twig', array()));
return $response;
}
示例15: getBacktraceView
public function getBacktraceView(array $backtrace)
{
$result = [];
$appRoot = realpath($this->appRoot . '/../');
foreach ($backtrace as $k => $v) {
$item = [];
if (isset($v['file'])) {
$item['location'] = str_replace($appRoot, '', $v['file']) . '(' . $v['line'] . ')';
if (strpos($item['location'], '/vendor') === 0) {
$item['hidden'] = true;
foreach ($this->excludes as $exclude) {
if (preg_match('#^/vendor/' . $exclude . '#', $item['location'])) {
$item['hidden'] = false;
break;
}
}
} else {
$item['hidden'] = false;
}
} else {
$item['location'] = '[internal function]';
$item['hidden'] = true;
}
if (isset($v['type'])) {
$item['element'] = $v['class'] . $v['type'] . $v['function'] . '()';
} else {
$item['element'] = $v['function'] . '()';
}
$result[] = $item;
}
return $this->environment->render('AkhristenkoDoctrineStacktraceBundle:Backtrace:view.html.twig', ['backtrace' => $backtrace, 'result' => $result]);
}