Title breadcrumbs

Overview

In the Smarty templating engine, you have three key variables for handling page titles and identifiers:

  1. page

  2. pagename

  3. page_title

Differences

  • page:

    • Purpose: Used as an identifier for the current page.

    • Use: Often employed in logic or conditional statements within the template to determine which page is being viewed. Can be Renamed from admin panel

  • pagename:

    • Purpose: A user-friendly name for the page.

    • Use: Suitable for display in the UI where the page name is needed, such as in headers or navigation menus. Can be Changed from admin panel

  • page_title:

    • Purpose: A complete title string.

    • Use: Often used for SEO purposes and displayed in the browser's title bar. It usually combines the page name with the site name or other contextual information. Can be Changed from admin panel

Use Case Example

Here is an example of how these variables might be used in a Smarty template, including formatting scenarios:

{if $page == 'home'}
  <!-- Display the page identifier in different formats -->
  {$page|upper} <!-- HOME -->
  {$page|lower} <!-- home -->
  {$page|capitalize} <!-- Home -->
  <h1>Welcome to the Home Page</h1>
{elseif $page == 'about'}
  <h1>About Us</h1>
{/if}

<!-- Display the user-friendly page name -->
<h2>{$pagename}</h2> <!-- Example output: Home -->

<!-- Display the full page title -->
<title>{$page_title}</title> <!-- Example output: Home - MySiteName -->

Using Breadcrumbs in Smarty Templates

Overview

Breadcrumbs are a navigational aid that helps users understand their current location within the hierarchy of a website. In this example, we create a breadcrumb array in PHP and pass it to a Smarty template for rendering.

The $breadcrumb array is structured as follows:

<nav aria-label="breadcrumb">
    <ol class="breadcrumb">
        {foreach from=$breadcrumb item=crumb}
            <li class="breadcrumb-item">
                <a href="{$crumb.url}">{$crumb.name}</a>
            </li>
        {/foreach}
    </ol>
</nav>

Explanation

  • {foreach}: This loop iterates over each element in the $breadcrumb array.

  • {$crumb.url}: Outputs the URL for each breadcrumb link.

  • {$crumb.name}: Outputs the display name for each breadcrumb link.

Last updated