Skip to content

Navigation & Menu Helpers


getMenu(?string $type = null): array

Fetches CMS navigation menus configured in the admin panel. Returns an array of menu items.

Parameters:

$type Returns
'top' Top navigation bar menu items only
'bottom' Footer menu items only
null Both combined

Menu Item Structure:

Each item in the array has these keys:

Key Type Description
menu_name string Internal menu name
menuName string Display label (same as menu_name)
menu_url string The URL this menu item links to
menu_status int 0\|1 Whether the menu is active
menu_position int 1\|2 1 = top nav, 2 = footer
menu_order int Display sort order
menu_permalink string Permalink for CMS content association

Usage:

{{-- Top Navigation --}}
<nav>
    <ul class="nav">
        @foreach(getMenu('top') as $menu)
            <li class="nav-item">
                <a class="nav-link" href="{{ $menu['menu_url'] ?? '#' }}">
                    {{ $menu['menuName'] }}
                </a>
            </li>
        @endforeach
    </ul>
</nav>

{{-- Footer Navigation --}}
<footer>
    @foreach(getMenu('bottom') as $menu)
        <a href="{{ $menu['menu_url'] ?? '#' }}" class="footer-link">
            {{ $menu['menuName'] }}
        </a>
    @endforeach
</footer>

getTopMenu(): array and getFooterMenu(): array

Low-level helpers used internally by getMenu(). You can use these directly if you need access to the raw Eloquent model array.

@php $topMenus = getTopMenu(); @endphp
@foreach($topMenus as $menu)
    <a href="{{ $menu->menu_url }}">{{ $menu->menu_name }}</a>
@endforeach

Fetches the HTML content body of a CMS page identified by its permalink. Used for CMS-driven content areas in the footer or sidebar.

{{-- Render a CMS page's content inline --}}
<div class="cms-content">
    {!! getMenuContent('about-us') !!}
</div>

{{-- Another common use: privacy policy --}}
{!! getMenuContent('privacy-policy') !!}

Warning

Always use {!! !!} (raw output) for getMenuContent(), as the value contains HTML. Make sure the content is trustworthy (it comes from the admin panel).


getLeftMenuActive(): string

Determines which category/menu item is currently active based on the current URL. Checks route parameters (cat, subcat, subsubcat) and the ?category= query string.

Returns the category permalink or an empty string.

@php $activeCategory = getLeftMenuActive(); @endphp

<ul class="sidebar-menu">
    @foreach(getCategory('', null, 'active')->categories as $cat)
        @php $permalink = $cat->category['permalink'] ?? ''; @endphp
        <li class="{{ $activeCategory === $permalink ? 'active' : '' }}">
            <a href="/category/{{ $permalink }}">{{ $cat->category['name'] ?? '' }}</a>
        </li>
    @endforeach
</ul>

isActivePage(string $label): bool

Returns true if the label matches the current page's label. Currently this only distinguishes the home page:

<li class="{{ isActivePage('Home') ? 'active' : '' }}">
    <a href="{{ customUrl('home') }}">Home</a>
</li>

isPageUrl(string $path): bool

Returns true if the given path matches the current request path exactly.

<li class="{{ isPageUrl('/about-us') ? 'active' : '' }}">
    <a href="/about-us">About Us</a>
</li>

getSiteNotification(): object

Returns the site-wide notification banner configuration from the admin panel.

Returns an object with:

Property Type Description
status int 0\|1 Whether the notification is enabled
Content string HTML content of the notification
backgroundcolor string CSS background color
fontcolor string CSS text color
@php $notification = getSiteNotification(); @endphp
@if($notification->status)
    <div style="
        background-color: {{ $notification->backgroundcolor }};
        color: {{ $notification->fontcolor }};
        padding: 10px;
        text-align: center;
    ">
        {!! $notification->Content !!}
    </div>
@endif

googleAnalytics(): string

Returns the complete Google Analytics script tag (or a disabled script if GA is not configured). Inject this anywhere in your layout, typically just before </body>.

{{-- In layout.blade.php, just before </body> --}}
{!! googleAnalytics() !!}

Note

This function automatically checks if Google Analytics is enabled in the admin settings, and whether a tracking ID is configured. If not, it outputs <script>var gTag = false;</script> to prevent errors in page-level GA tracking code.