PHP code example of brandaddition / module-svelte

1. Go to this page and download the library: Download brandaddition/module-svelte 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/ */

    

brandaddition / module-svelte example snippets



declare(strict_types=1);

namespace Vendor\Module\ViewModel;

use Magento\Framework\View\Element\Block\ArgumentInterface;

class Example implements ArgumentInterface
{
    /**
     * @return string
     **/
    public function getMessage(): string
    {
        return 'Hello from Magento';
    }
}


declare(strict_types=1);

namespace Vendor\Module\Model\PropResolver;

use BA\Svelte\Api\PropResolverInterface;
use Magento\Framework\View\Element\Template;

class ExamplePropResolver implements PropResolverInterface
{
    public function resolve(string $propName, array $definition, Template $block): mixed
    {
        $value = $definition['value'] ?? null;

        return is_string($value) ? strtoupper($value) : null;
    }
}
svelte
<script>
    import ContainerRenderer from '@modules/BA_Svelte/svelte/container-renderer.svelte';

    let {
        heading = 'Example',
        get_container: getContainer,
    } = $props();
</script>

<section>
    <h2>{heading}</h2>
    <ContainerRenderer items={getContainer?.('content') ?? []} />
</section>
xml
<type name="BA\Svelte\Model\PropResolverPool">
    <arguments>
        <argument name="resolvers" xsi:type="array">
            <item name="example" xsi:type="object">Vendor\Module\Model\PropResolver\ExamplePropResolver</item>
        </argument>
    </arguments>
</type>
text
pub/static/<area>/<Vendor>/<Theme>/<Locale>/BA_Svelte/svelte/container-renderer.svelte

final_price => **REQUIRED**
regular_price => default = `0,`
has_special_price => default = `false,`
currency_code => default = `window.__baCurrentCurrency,`
currency_symbol => default = `'',`
locale => default = `window.__baCurrentLocale,`
precision => default = `2,`
show_minimal_price => default = `false,`
use_link_for_as_low_as => default = `false,`
minimal_price => default = `null,`
minimal_price_label => default = `_('As low as'),`
product_url => default = `'',`
special_price_label => default = `_('Special Price'),`
old_price_label => default = `_('Was'),`