PHP code example of carlos-andres / nova-html-field
1. Go to this page and download the library: Download carlos-andres/nova-html-field library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
carlos-andres / nova-html-field example snippets
use Vendor\NovaHtmlField\HtmlField;
// Static content
HtmlField::make('Notice')
->content('<p style="color: #059669;">Settings saved successfully</p>');
// Dynamic from model
HtmlField::make('Preview')
->html(fn ($model) => '<strong>'.e($model->title).'</strong>');
// From model attribute
HtmlField::make('Description', 'html_content');
// This may NOT work (classes might not exist in Nova's CSS)
HtmlField::make('Card')
->content('<div class="bg-blue-100 p-4 rounded-lg">Hello</div>');
// This WILL work (inline styles always render)
HtmlField::make('Card')
->content('<div style="background: #dbeafe; padding: 16px; border-radius: 8px;">Hello</div>');
// Using emoji (works)
HtmlField::make('Files')
->content('<h3>📁 Files Section</h3>');
HtmlField::make('Images')
->content('<h3>🖼️ Images Section</h3>');
// SVG will be stripped (won't work without disabling sanitization)
HtmlField::make('Files')
->content('<svg>...</svg> Files Section');
// Good - escaped
HtmlField::make('Title')
->html(fn ($m) => '<strong>'.e($m->title).'</strong>');
// Bad - XSS vulnerable
HtmlField::make('Title')
->html(fn ($m) => '<strong>'.$m->title.'</strong>');
// Only for content you completely control
HtmlField::make('Trusted HTML')
->html(fn ($m) => $m->trusted_html)
->withoutSanitization();