* Truncates the string to a given length, while ensuring that it does not split words. * * @param string $string The string to truncate * @param int $length The maximum number of characters for the truncated string * @param string $suffix The string that should be appended to `$string`, if it must be truncated * @param bool $splitSingleWord Whether to split up `$string` if it only contains one word * @return string The truncated string * @since 3.5.10 */ public function truncateFilter(string $string, int $length, string $suffix = '…', bool $splitSingleWord = true): string { // Override default behavior where the substring would be returned in this case if ($string === '' || $length <= 0) { return $string; } return StringHelper::safeTruncate($string, $length, $suffix, $splitSingleWord); }
</div> <p class="news-snippet-type {{entry.category}}"><span></span><span>{{entry.category.label}}</span> <b>{{entry.postDate | date('d.m.y')}}</b></p> <h2 class="news-preview-title">{{ entry.title }}</h2> {% if entry.longText is not empty %} <p>{{ entry.longText }}</p> {% else %} <p>{{ entry.body | truncate('words', '20', '...', true) }}</p> {% endif %} <p class="secondary-button">Read more</p> {% endif %} </a> </div>
return ob_get_clean(); } protected function displayWithErrorHandling(array $context, array $blocks = []) { try { $this->doDisplay($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
{ return $this->blocks; } public function display(array $context, array $blocks = []) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } public function render(array $context) { $level = ob_get_level(); if ($this->env->isDebug()) {
{% if related is not empty %} <h3 class="section-intro">Related articles</h3> <ul> {% for entry in related %} <li> {% include "01-atoms/news-preview" with { 'entry': entry } %} </li> {% endfor %} </ul> {% else %} <h3 class="section-intro">Latest articles</h3> <ul>
return ob_get_clean(); } protected function displayWithErrorHandling(array $context, array $blocks = []) { try { $this->doDisplay($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
{ return $this->blocks; } public function display(array $context, array $blocks = []) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } public function render(array $context) { $level = ob_get_level(); if ($this->env->isDebug()) {
</div> </div> </div> </div> <div class="news-preview col-sm-offset-1 col-sm-4"> {% include "02-molecules/related-articles" %} </div> </div> </section>
if (null !== $template && !$template instanceof self) { throw new \LogicException('A block must be a method on a \Twig\Template instance.'); } if (null !== $template) { try { $template->$block($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($template->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
{% include "01-atoms/grid-lines" %} {% include "01-atoms/signpost" with { 'text': entry.signpost } %} <div class="wrapper"> {% block content %}{% endblock %} </div> {% include "03-organisms/more" %} {% include "03-organisms/footer" %} {% include "01-atoms/footnotes" %}
if (null !== $template && !$template instanceof self) { throw new \LogicException('A block must be a method on a \Twig\Template instance.'); } if (null !== $template) { try { $template->$block($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($template->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
<!Doctype html> <html lang="" class="no-js"> {% include "02-molecules/head" %} <body class="page-{{bodyClass}} animated fadeIn"> {% block body %}{% endblock %} <div id="contact-modal"> <a class="close-modal" href="#" data-modal-toggle></a> <div class="overlay"> <div class="container grid-lines"> <div class="row">
return ob_get_clean(); } protected function displayWithErrorHandling(array $context, array $blocks = []) { try { $this->doDisplay($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
{ return $this->blocks; } public function display(array $context, array $blocks = []) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } public function render(array $context) { $level = ob_get_level(); if ($this->env->isDebug()) {
{% extends "05-layouts/base" %} {% block body %} {% include "03-organisms/header" %} {% include "01-atoms/grid-lines" %} {% include "01-atoms/signpost" with {
return ob_get_clean(); } protected function displayWithErrorHandling(array $context, array $blocks = []) { try { $this->doDisplay($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
{ return $this->blocks; } public function display(array $context, array $blocks = []) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } public function render(array $context) { $level = ob_get_level(); if ($this->env->isDebug()) {
{% do craft.entryCount.increment(entry.id) %} {% extends "05-layouts/no-hero" %} {% set bodyClass = "news-article" %} {% set image = entry.headerImage.one() %} {% block content %}
return ob_get_clean(); } protected function displayWithErrorHandling(array $context, array $blocks = []) { try { $this->doDisplay($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
{ return $this->blocks; } public function display(array $context, array $blocks = []) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } public function render(array $context) { $level = ob_get_level(); if ($this->env->isDebug()) {
if ($this->env->isDebug()) { ob_start(); } else { ob_start(function () { return ''; }); } try { $this->display($context); } catch (\Throwable $e) { while (ob_get_level() > $level) { ob_end_clean(); } throw $e;
} public function render(array $context = []): string { // using func_get_args() allows to not expose the blocks argument // as it should only be used by internal code return $this->template->render($context, \func_get_args()[1] ?? []); } public function display(array $context = []) { // using func_get_args() allows to not expose the blocks argument // as it should only be used by internal code
* @throws LoaderError When the template cannot be found * @throws SyntaxError When an error occurred during compilation * @throws RuntimeError When an error occurred during rendering */ public function render($name, array $context = []): string { return $this->load($name)->render($context); } /** * Displays a template. * * @param string|TemplateWrapper $name The template name
// Render and return $renderingTemplate = $this->_renderingTemplate; $this->_renderingTemplate = $template; try { $output = $this->getTwig()->render($template, $variables); } finally { $this->_renderingTemplate = $renderingTemplate; $this->setTemplateMode($oldTemplateMode); } $this->afterRenderTemplate($template, $variables, $templateMode, $output);
$isRenderingPageTemplate = $this->_isRenderingPageTemplate; $this->_isRenderingPageTemplate = true; try { $this->beginPage(); echo $this->renderTemplate($template, $variables); $this->endPage(); } finally { $this->_isRenderingPageTemplate = $isRenderingPageTemplate; $this->setTemplateMode($oldTemplateMode); $output = ob_get_clean(); }
) { $view->registerAssetBundle(ContentWindowAsset::class); } // Render and return the template try { $response->content = $view->renderPageTemplate($behavior->template, $behavior->variables, $behavior->templateMode); } catch (Throwable $e) { if (!$e->getPrevious() instanceof ExitException) { // Bail on the template response $response->format = Response::FORMAT_HTML; throw $e; }
if (isset($this->formatters[$this->format])) { $formatter = $this->formatters[$this->format]; if (!is_object($formatter)) { $this->formatters[$this->format] = $formatter = Yii::createObject($formatter); } if ($formatter instanceof ResponseFormatterInterface) { $formatter->format($this); } else { throw new InvalidConfigException("The '{$this->format}' response formatter is invalid. It must implement the ResponseFormatterInterface."); } } elseif ($this->format === self::FORMAT_RAW) { if ($this->data !== null) { $this->content = $this->data;
/** * @inheritdoc */ protected function prepare(): void { parent::prepare(); $this->_isPrepared = true; } /** * Clear the output buffer to prevent corrupt downloads. *
public function send() { if ($this->isSent) { return; } $this->trigger(self::EVENT_BEFORE_SEND); $this->prepare(); $this->trigger(self::EVENT_AFTER_PREPARE); $this->sendHeaders(); $this->sendContent(); $this->trigger(self::EVENT_AFTER_SEND); $this->isSent = true; }
$response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send(); $this->state = self::STATE_END; return $response->exitStatus; } catch (ExitException $e) { $this->end($e->statusCode, isset($response) ? $response : null);
// Load shared bootstrap require dirname(__DIR__) . '/bootstrap.php'; // Load and run Craft /** @var craft\web\Application $app */ $app = require CRAFT_VENDOR_PATH . '/craftcms/cms/bootstrap/web.php'; $app->run();
$_GET = [ 'p' => 'news/2012/happy-dasain-tihar-2069', ];