PHP code example of fsmdev / laravel-page-attributes

1. Go to this page and download the library: Download fsmdev/laravel-page-attributes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fsmdev / laravel-page-attributes example snippets


# config/app.php

'providers' => [
  ...
  Fsmdev\LaravelPageAttributes\PageAttributesServiceProvider::class,
  ...
];

'aliases' => [
  ...
  'PageAttributes' => Fsmdev\LaravelPageAttributes\Facades\PageAttributes::class,
  ...
];


use Fsmdev\LaravelPageAttributes\Facades\PageAttributes;

PageAttributes::set('title', 'Awesome Page');

PageAttributes::set('h1', $post->name);

# Own attribute
PageAttributes::set('my_attribute', 'My Value');

# config/page_attributes.php

'default' => [

  # Default value for title
  'title' => 'Awesome Page',
  
  # Override charset
  'charset' => 'windows-1251',
],

# config/page_attributes.php

'html_templates' => [
    
    # Overriding template for h1
    'h1' => '<h1 class="some-class"><{value}/h1>',
    
    # Creating template for own attribute
    'my_attribute' => '<p>{value}</p>',
],

PageAttributes::set('my_attribute', 'My Value');

# app/ConstantsCollections/PageAttributesContext.php

const INDEX = 5;
const CONTACTS = 10;
const BLOG = 15;

protected static function propertiesName()
{
    return [
        self::INDEX => 'Home Page',
        self::CONTACTS => 'Contacts Page',
        self::BLOG => 'Blog',
    ];
}

PageAttributes::context(PageAttributesContext::INDEX);

# config/page_attributes.php

'default_variables' => [
    'site_name' => 'Awesome Site',
],

# Controller

PageAttributes::context(PageAttributesContext::POST_SHOW, [
    'post_name' => $post->name, // F.e. Post Name is 'About Me'
]);