Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
olexoliinyk0 opened this issue Feb 20, 2025 · 1 comment

Comments

@olexoliinyk0
Copy link

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!

@kudashevs
Copy link
Owner

kudashevs commented Feb 21, 2025

@olexoliinyk0 Thank you very much for sharing your solution 👍

I need to think whether it is worth adding the support for components. On one hand, using Blade components seems to be a trend. On the other hand, it is going to complicate the package because this task requires at least one additional component (ideally, two components - for a container and for a link) and it is going to introduce some additional configuration steps. I will leave this issue open for a couple of days. Once again, thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants