Skip to content
W
Sign in

Templates and Markdown

Learn which Markdown syntax WBengine supports, how source becomes safe HTML, and how file and database content differ.

Native templates

The native engine compiles .tpl files to PHP and can use OPcache. {$value} is HTML-escaped by default; |raw is for HTML that the application has deliberately rendered or trusted.

<h1>{$title}</h1>
{$bodyHtml|raw}
{include 'Shared/footer.tpl'}

Markdown files

A .md file can be rendered directly by the native renderer or included in an HTML template:

{include 'Central/notice.md'}

Markdown is parsed as content. PHP tags, template variables, and template directives inside it are not executed. The built-in parser escapes raw HTML and restricts link protocols.

From a box, use the shared service when you already have a Markdown string:

$html = $this->getSite()->getParent()->getMarkdown()->render($source);

Markdown in article rows

Set content_format to markdown in cms_articles or cms_article_translations. Existing rows remain legacy_html after migration. Do not mark old HTML as Markdown without converting and reviewing its content.

Supported Markdown syntax

The bundled parser supports CommonMark 0.31.2 and GitHub Flavored Markdown tables, strikethrough, and task lists. Common block forms include headings, paragraphs, thematic breaks, blockquotes, ordered and unordered lists, indented code, and fenced code blocks. Tables use the pipe and delimiter-row syntax.

Inline forms include emphasis, strong emphasis, inline code, links, images, escaped punctuation, automatic links and email addresses, and hard line breaks. GFM adds ~~strikethrough~~ and task list markers such as - [x] done. A language after a fenced code marker is retained as a language-* class.

## Heading

A paragraph with **strong**, *emphasis*, `code`, and [a link](https://example.com).

- first item
- second item

| Name | Value |
| --- | --- |
| site | WBengine |

- [x] reviewed

```php
echo "Hello";
```

How rendering works

The parser turns source into a document tree. The HTML renderer then emits a limited set of elements and escapes text and attributes. Raw HTML in Markdown is displayed as text, and links are limited to safe URL schemes such as relative URLs, HTTP, HTTPS, and mailto. Markdown never executes PHP or template directives. The output of the built-in renderer is safe to print with |raw; do not use |raw for arbitrary input.

For a .md file, the native renderer selects Markdown by the file extension, whether the file is rendered directly or included from a .tpl file. For database articles, content_format is stored separately on each article and translation row. When it is markdown, the Article box parses the article text fields before the template prints the generated HTML. Rows marked legacy_html keep the existing HTML behavior. Review and convert legacy HTML before changing its format.

Live on this request

Template syntax, rendered now

The table shows native template escaping; the example below is a Markdown source included by a template.

SourceResult
{$hostile}<script>alert("x")</script> Tom & "Jerry"
{$html}<strong>trusted</strong> markup
{$html|raw}trusted markup
{$name|default:'anonymous'|upper}ANONYMOUS
{$text|truncate:24}WBengine compiles templa...
{$items|join:' / '}Site / Section / Box
{$price|number:2}1,234.50
{$time|ldate:'long'}October 27, 2026
{foreach $items as $i}{$i}{/foreach}SiteSectionBox
{if $price > 1000}...{/if}above 1000

Markdown as a template source

This file is included by Templates.tpl. The native renderer parses it as Markdown content, so template tags and PHP inside a .md file are not executed.