Globals

Textstem globals are items of content available anywhere at anytime. There are several different types of global, including -

Base types:

  • array
  • boolean
  • html
  • json
  • number
  • string

Rich types

  • list
  • pages

The type defines both the underlaying data type (and how it is stored), as well as the UI elements used to enter the value and how it should be treated. For example, the pages type will store an array of IDs as a JSON array in the database, but the UI widget to select the IDs is a 'page picker' widget and the value is a collection of pages. 

By default, globals are loaded into a memory cache with each page load and available for use in page templates and page components. Globals can be marked as 'lazy' and are only loaded when needed.

Use Cases

To create a custom menu, a 'pages' collection can be used. For example, a global called 'footer-menu' could be used to create a special list of pages to be displayed on each page. The page layout might include something like this to display the collected pages:

<nav class="-mb-6 columns-2 sm:flex sm:justify-center sm:space-x-12 " aria-label="Footer">
            @foreach($globals['footer-menu'] ?? [] as $item)
            <div class="pb-6">
                <a href="{{$item->url}}" class="text-sm leading-6 text-gray-600 hover:text-gray-900">{{$item->title}}</a>
            </div>
            @endforeach
</nav>

Creating New Types

To create a new type, create a class in \app\Domain\Globals\Types. This class should be named {TypeName}Type and should extend Medialight\Textstem\Domain\Globals\GlobalType. For example, to crete a global type to store positional information, create a class called PositionType. This should have a static method called make that returns a new instance of itself, passing in the 'source' value (a string) and the desired value (array of two floats)