Help With Form URLS

I have a blog post that uses markdown syntax and I created the ability (spatie) to add attachments to the post. Now I need a way to list them so the user can copy the url into the blog post. This is whave I have so far:
Forms\Components\Placeholder::make('attachments')
->label(__('filament-blog::filament-blog.attachment_list'))
->content(function (?Post $record): string {
if (!$record) {
return 'None';
}

$attachments = $record->getMedia('attachments');

if ($attachments->isEmpty()) {
return 'None';
}

// Build an array of URLs for each media
$attachmentUrls = $attachments->map(function (Media $media) {
return sprintf('<li>%s</li>', $media->getFullUrl());
});


// You can now access the array of URLs as needed
// For example, join them with line breaks:
return sprintf('<ul>%s</ul>', $attachmentUrls->join("\n"));
}),
Forms\Components\Placeholder::make('attachments')
->label(__('filament-blog::filament-blog.attachment_list'))
->content(function (?Post $record): string {
if (!$record) {
return 'None';
}

$attachments = $record->getMedia('attachments');

if ($attachments->isEmpty()) {
return 'None';
}

// Build an array of URLs for each media
$attachmentUrls = $attachments->map(function (Media $media) {
return sprintf('<li>%s</li>', $media->getFullUrl());
});


// You can now access the array of URLs as needed
// For example, join them with line breaks:
return sprintf('<ul>%s</ul>', $attachmentUrls->join("\n"));
}),
this will output the url fine but its showing the html so I am gussing this is escaped. I was wondering if it would be possible to create a table here or display the images and then utilize a click to copy url.
6 Replies
awcodes
awcodes16mo ago
Wrap the return in a new HtmlString()
datarecall
datarecallOP16mo ago
@awcodes
Forms\Components\Placeholder::make('attachments')
->label(__('filament-blog::filament-blog.attachment_list'))
->content(function (?Post $record): string {
if (!$record) {
return 'None';
}

$attachments = $record->getMedia('attachments');

if ($attachments->isEmpty()) {
return 'None';
}

// Build an array of URLs for each media
$attachmentUrls = $attachments->map(function (Media $media) {
return sprintf('<li>%s</li>', $media->getFullUrl());
});

return new HtmlString(sprintf('<ul>%s</ul>', $attachmentUrls->join("\n")));
}),
Forms\Components\Placeholder::make('attachments')
->label(__('filament-blog::filament-blog.attachment_list'))
->content(function (?Post $record): string {
if (!$record) {
return 'None';
}

$attachments = $record->getMedia('attachments');

if ($attachments->isEmpty()) {
return 'None';
}

// Build an array of URLs for each media
$attachmentUrls = $attachments->map(function (Media $media) {
return sprintf('<li>%s</li>', $media->getFullUrl());
});

return new HtmlString(sprintf('<ul>%s</ul>', $attachmentUrls->join("\n")));
}),
Still escapes the html it seems
awcodes
awcodes16mo ago
hmm. maybe the sprintf needs to run outside the HtmlString
Patrick Boivin
Patrick Boivin16mo ago
@datarecall Not sure but try removing the string return type:
->content(function (?Post $record) {
->content(function (?Post $record) {
datarecall
datarecallOP16mo ago
ahh that could be it let me test that
Dennis Koch
Dennis Koch16mo ago
Is this solved?
Want results from more Discord servers?
Add your server