Blade

Learn how to run a snippet once the client-side SDK is ready.

The @croct Blade directive defers a snippet until the client-side SDK has loaded, then runs it with the croct instance available, regardless of the loading mode.

Signature

Wrap a block of JavaScript between the @croct and @endcroct directives:

@croct    // your JavaScript using the croct instance@endcroct

To set a Content Security Policy nonce on the generated script tag, pass it as an argument:

@croct($nonce)    // your JavaScript using the croct instance@endcroct

Example

Here is a basic example of how to use this directive, passing server-side values into the snippet with Blade:

resources/views/checkout/confirmation.blade.php
@croct    croct.track('orderPlaced', {        order: {            orderId: @json($order->id),            total: @json($order->total),        },    });@endcroct

Parameters

The following list describes the supported parameters:

nonce(optional)
string

A Content Security Policy nonce added to the generated script tag.

Default:null