Skip to content

Allow using Blade Component syntax in config that is properly Blade-parsed #15

Closed
@E4SdJG528X9FsnpaBz6yxw

Description

@E4SdJG528X9FsnpaBz6yxw

I use blade-ui-kit/blade-icons for my custom icons sets, and for social icons I've tried to use them too, but when I tried to put Blade Component syntax in the config/share-buttons.php within templates values - like so

// config/share-buttons.php
// ... 
'twitter' => '<a href=":url" class="social-button:class":id:title:rel><x-buk-icon name="social-twitter" width="24" height="24"/></a>',
// ...

it just rendered nothing - because the whole string itself is not handled as a Blade template.

To achieve the intended I've done the following:

// resources/components/social-share-buttons.blade.php
@props([
    'url' => '',
    'title' => '',
    'socials' => [
        'twitter' => [],
    ],
])

@php
    $renderer = ShareButtons::page($url, $title);

    foreach ($socials as $name => $options) {
        if (!is_string($name)) {
            $renderer->{$options}();
        } else {
            $renderer->{$name}($options);
        }
    }

    $rendered = Blade::render($renderer->render());
@endphp

{!! $rendered !!}

Then it processed the final string via Blade's render and displayed the icon as I've wanted.

Cheers! Great lib!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions