Skip to main content

Core Concepts: Built-in Page Variables

During the build phase, Coralite automatically injects several context variables into the values object of your components. These variables provide essential information about the current page's URL and file path, making it easy to create dynamic logic like highlighting active navigation links or generating breadcrumbs.

These core variables all follow the page_* snake_case naming convention and are provided natively by the framework.

Available Page Variables #

Metadata Variables #

In addition to the path-related variables, if you are using the built-in metadata plugin, it injects the following special variables from the page's <head>:

Example Usage #

Because these variables are injected directly into the values object, you can reference them seamlessly within your components using tokens or computed properties.

Here is an example of a navigation link component that automatically adds an "active" class if the current URL matches its target URL:

HTML
Code copied!
<!-- src/components/nav-link.html -->
<template id="nav-link">
  <a href="{{ href }}" class="link {{ activeClass }}">
    <slot></slot>
  </a>
</template>

<script type="module">  
  import { defineComponent } from 'coralite/plugins'
  
  export default defineComponent({
    tokens: {
      // Computed token that checks if the href prop matches the current URL
      activeClass: (values) => (values.href === values.page_url_pathname ? 'active' : '')
    }
  })
</script>

You can also use these variables purely declaratively inside your static templates:

HTML
Code copied!
<!-- src/components/page-info.html -->
<template id="page-info">
  <div class="page-info-box">
    <p>Current URL: <strong>{{ page_url_pathname }}</strong></p>
    <p>Source File: <strong>{{ page_filename }}</strong></p>
    <p>Language: <strong>{{ page_lang }}</strong></p>
  </div>
</template>

Start Building with Coralite!

Use the scaffolding script to get jump started into your next project with Coralite

Copied commandline!