PHP code example of 68publishers / webpack-encore-bundle
1. Go to this page and download the library: Download 68publishers/webpack-encore-bundle 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/ */
68publishers / webpack-encore-bundle example snippets
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use SixtyEightPublishers\WebpackEncoreBundle\Event\RenderAssetTagEvent;
final class ScriptNonceSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
RenderAssetTagEvent::class => 'onRenderAssetTag',
];
}
public function onRenderAssetTag(RenderAssetTagEvent $event): void
{
if ($event->isScriptTag()) {
$event->setAttribute('nonce', 'lookup nonce');
}
}
}
latte
{*
{encore_js_files(string $entryName, ?string $entrypointName): array}
{encore_css_files(string $entryName, ?string $entrypointName): array}
{encore_entry_exists(string $entryName, ?string $entrypointName): bool}
*}
{foreach encore_js_files('entry1') as $file}
{var $asset = asset($file)}
{/foreach}
{foreach encore_css_files('entry1') as $file}
{var $asset = asset($file)}
{/foreach}
{* Render tags for entry `entry2` only if the entry exists (prevents an exception throwing in a strict mode) *}
{if encore_entry_exists('entry2')}
{encore_js 'entry2'}
{/if}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.