Skip to content

Formatting & Utility Helpers


Text & String Helpers

tagShortText(string $text, int $limit = 27): string

Truncates a string to the specified character limit and appends ... if truncated. Multibyte-safe.

{{-- In a product card, keep the name short --}}
<h6>{{ tagShortText($product['name'], 50) }}</h6>

{{-- Default limit is 27 characters --}}
<small>{{ tagShortText($product['subtitle']) }}</small>

translate(string $text): string

A no-op translation stub. Returns the input string unchanged. Provided for legacy compatibility where Twig used {% trans 'text' %}.

{{ translate('Add to Cart') }}  {{-- Returns: Add to Cart --}}

Pricing & Number Helpers

tagPrice(mixed $value, bool $thousands = false): string

Formats a numeric value as a price string with 2 decimal places. Optionally includes thousands separator.

{{-- Basic usage --}}
${{ tagPrice(1250) }}          {{-- Output: 1250.00 --}}
${{ tagPrice(12.5) }}          {{-- Output: 12.50 --}}

{{-- With thousands separator --}}
${{ tagPrice(1250.99, true) }} {{-- Output: 1,250.99 --}}

{{-- Common usage in a product listing --}}
<span class="price">${{ tagPrice($product['specialPrice'] ?? $product['normalPrice'] ?? 0) }}</span>

{{-- Show crossed-out original price if discounted --}}
@if(($product['discountPercent'] ?? 0) > 0)
    <del>${{ tagPrice($product['normalPrice']) }}</del>
    <strong class="text-danger">${{ tagPrice($product['specialPrice']) }}</strong>
@else
    <strong>${{ tagPrice($product['normalPrice']) }}</strong>
@endif

Address Helpers

tagAddressFormat(mixed $address, mixed $edit = null, mixed $delete = null): string

Formats an address object or array into HTML with data- attributes that can be used by JavaScript to populate edit forms. This is the standard way to render addresses in the address book.

The function extracts: fname, lname, address1, address2, city, state, country, zipcode, phone, fax, company.

Warning

Always use {!! !!} for this function as it returns HTML.

{{-- In an address book list --}}
@foreach($addresses as $address)
    <div class="address-card" data-id="{{ $address->address_id }}">
        {!! tagAddressFormat($address) !!}

        {{-- Optional edit/delete buttons --}}
        <button class="btn btn-sm btn-secondary" onclick="editAddress(this)">Edit</button>
        <button class="btn btn-sm btn-danger" onclick="deleteAddress(this)">Delete</button>
    </div>
@endforeach

The rendered HTML contains <span> tags with data-addkey, data-addtype, and data-addval attributes that can be read by JavaScript to pre-fill edit forms.


Image & Asset Helpers

getPath(mixed $value): ?string

Resolves the URL for an asset stored in the ThemeAssetService. Used for assets configured in the admin panel (like logo images).

{{-- Get the URL for a configured image --}}
@if(getPath($themes->header_image ?? null))
    <img src="{{ getPath($themes->header_image) }}" alt="Logo">
@endif

getAlt(mixed $value, string $fallback = ''): string

Returns the alt text for an image. If the image record has alt text configured, it returns that. Otherwise returns the fallback string.

<img src="{{ $product['image'] }}"
     alt="{{ getAlt($product['image'], $product['name']) }}">

hasAsset(mixed $value): bool

Returns true if the given value resolves to an actual asset.

@if(hasAsset($themes->banner_image ?? null))
    <img src="{{ getAsset($themes->banner_image) }}" alt="Banner">
@endif

getAsset(mixed $value): ?string

Alias for getPath(). Resolves an asset value to its URL.

<img src="{{ getAsset($themes->logo ?? null) }}" alt="Logo">

noproductimage(string $key = 'default_image'): ?string

Returns the fallback product image URL. Checks theme settings first, then admin settings, then falls back to the hardcoded default at /images/no_product_image_large.jpg.

<img src="{{ $product['image'] ?: noproductimage() }}"
     alt="{{ $product['name'] }}">

thumbnails(string $path, string $resolution = '180'): ?string

Looks for a thumbnail version of an image file in the public files/ directory. Returns null if not found.

<img src="{{ thumbnails($product['image']) ?? noproductimage() }}"
     alt="{{ $product['name'] }}"
     style="width: 180px;">

uploads(): ThemeUploads

Returns the ThemeUploads service instance for resolving uploaded file paths.

@php $imageUrl = uploads()->get($imageFileName, 'product', $itemNo); @endphp
@if($imageUrl)
    <img src="{{ $imageUrl }}" alt="Product Image">
@endif

Twig-Compatibility Helpers

These functions bridge patterns from the legacy Twig system.

twig_length(mixed $value): int

Returns the "length" of a value: - Array/Countable → count() - String → mb_strlen() - Object → number of public properties - null → 0

@if(twig_length($product['review'] ?? []) > 0)
    <p>{{ twig_length($product['review']) }} reviews</p>
@endif

twig_default(mixed $value, mixed $default = ''): mixed

Returns $default if $value is empty; otherwise returns $value. Equivalent to the Twig default filter.

{{ twig_default($product['subtitle'], 'No subtitle') }}

twig_date(mixed $value, string $format): string

Formats a date value using PHP's date() format string. Accepts timestamps, date strings, or DateTimeInterface objects.

{{-- Format an order date --}}
{{ twig_date($order->created_at, 'M j, Y') }}   {{-- e.g. Jun 24, 2025 --}}
{{ twig_date($order->created_at, 'Y-m-d') }}

twig_first(mixed $value): mixed

Returns the first element of an array, or the first character of a string.

@php $firstImage = twig_first($product['images'] ?? []); @endphp

twig_object_to_array(mixed $value): array

Recursively converts objects to arrays. Used for working with variation data on the product page.

@foreach(twig_object_to_array($variation->variation) as $key => $value)
    <span>{{ $key }}: {{ $value }}</span>
@endforeach

tagMessageSetting(string $name): string

Reads a setting value from the database settings table and formats newlines as <br> tags. Use {!! !!} for output.

{!! tagMessageSetting('welcome_message') !!}

Pagination

paginationControl(mixed $paginator, ...): string

Renders a pagination control using a Blade partial. Used on pages with long lists of results.

{{-- Render pagination controls --}}
{!! paginationControl($paginator, 'sliding', 'partial.paginator', [
    'pageRange' => 5
]) !!}

eventElement(string $name): string

A legacy stub for tracking DOM events. Currently returns an empty string ''.

<button {!! eventElement('add_to_cart') !!}>Buy</button>

Legacy Compatibility

legacy_url(string $path, array $params = [], array $options = []): string

Generates URLs from legacy Laminas route names. If the route name exists in the Laravel route collection, it uses route(). Otherwise, constructs the URL manually.

<a href="{{ legacy_url('user/login') }}">Login</a>