Blade Usage
Directives
@djot Directive
Converts Djot markup to HTML. Safe mode is enabled by default, protecting against XSS.
@djot($article->body)The directive outputs raw HTML — the surrounding <?php echo ?> is emitted for you.
@djotRaw Directive
Converts Djot markup to HTML without safe mode. Use only for trusted content.
{{-- Only use for content you fully control --}}
@djotRaw($trustedArticle->body)This bypasses XSS protection — dangerous URLs (javascript:, data:) and raw HTML blocks are preserved. Never use with user-generated content.
@djotText Directive
Converts Djot markup to plain text. The result is HTML-escaped via Laravel's e() helper. Useful for:
- Search indexing
- Meta descriptions
- Email plain text fallbacks
- Previews/excerpts
<meta name="description" content="@djotText(Str::limit($article->body, 160))">Facade
The Djot facade exposes the same functionality for inline use:
{!! Djot::toHtml($content) !!}
{!! Djot::toHtml($content, 'docs') !!}
{!! Djot::toHtmlRaw($trustedContent) !!}
{{ Djot::toText($content) }}Remember: escapes HTML. For toHtml() / toHtmlRaw(), use {!! !!} or the directives.
Common Patterns
Conditional Rendering
@if($article->body)
<div class="content">
@djot($article->body)
</div>
@endifWith Default Value
@djot($article->body ?? '')Excerpt with Fallback
@php($excerpt = $article->excerpt ?? Str::limit(Djot::toText($article->body), 200))
<p class="excerpt">{{ $excerpt }}</p>User-Generated Content
The default @djot directive is safe for user content:
{{-- Safe - XSS protection enabled by default --}}
@djot($comment->text)Trusted CMS Content
For content from trusted sources (admin, editors):
{{-- Quick way - use @djotRaw --}}
@djotRaw($article->body)
{{-- Or use a named converter with extensions --}}
{!! Djot::toHtml($article->body, 'docs') !!}Inline Content
For short inline content like titles or labels:
<h1>@djot($article->title)</h1>Note: This wraps the content in <p> tags. If you need truly inline output, strip the wrapper:
<h1>{!! Str::of(Djot::toHtml($article->title))->replaceMatches('#^<p>|</p>$#', '')->trim() !!}</h1>Next Steps
- Service Usage - use the converter in PHP code
- Safe Mode - understand XSS protection