PHP code example of contenir / contenir-contact

1. Go to this page and download the library: Download contenir/contenir-contact 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/ */

    

contenir / contenir-contact example snippets


$business = Contenir\Contact\ContactSettings::fromSettings($settings);

$business->name;                         // "Studio Esteta"
(string) $business->taxId;               // "ABN 12 345 678 901"
$business->offices->primary()?->address?->oneLine();

foreach ($business->offices as $office) {
    $office->name;                       // "Melbourne studio"
    (string) $office->telephone;         // "03 9428 0228", the office's own or the business's
    $office->telephone?->uri();          // "tel:+61394280228"
    $office->hour->summary();            // "Mon–Fri 9:00am–5:30pm"
    $office->hour->isOpenAt(new DateTimeImmutable());
}

'site' => ['title' => 'Studio Esteta', 'locale' => 'en_AU', 'timezone' => 'Australia/Melbourne'],
'contact' => [
    'business' => [
        'name'            => 'Studio Esteta',              // falls back on site.title
        'legal_name'      => 'Studio Esteta Pty Ltd',
        'tax_id'          => '12 345 678 901',
        'type'            => 'LocalBusiness',              // a schema.org organisation type
        'additional_type' => ['Q4387609'],                 // Wikidata entries
        'telephone'       => '+61 3 9428 0228',
        'email'           => '[email protected]',
        'timezone'        => 'Australia/Melbourne',        // falls back on site.timezone
        'hour'            => [
            ['day' => ['Mo', 'Tu', 'We', 'Th', 'Fr'], 'opens' => '09:00', 'closes' => '17:30'],
        ],
    ],
    'office' => [
        [
            'id'          => 'k3f9q2',                     // fixed when the office is added
            'name'        => 'Melbourne studio',
            'primary'     => true,
            'search'      => true,                         // shown to search engines
            'street'      => '402 Queens Parade',
            'locality'    => 'Fitzroy North',
            'region'      => 'VIC',
            'postcode'    => '3068',
            'country'     => 'AU',                         // falls back on the site's locale
            'geolocation' => ['latitude' => '-37.7787', 'longitude' => '144.9874'],
        ],
    ],
],

$offices = $business->offices->pick($block['fields']['office']);
// ['choose' => 'all'] | ['choose' => 'primary'] | ['choose' => 'some', 'id' => ['k3f9q2', 'p8d1x7']]

'contenir_contact' => [
    'format' => [
        'header' => ['part' => ['telephone']],
        'footer' => ['part' => ['name', 'address'], 'template' => 'partials/office-footer'],
        'legal'  => ['subject' => 'business', 'part' => ['legal_name', 'tax_id'], 'label' => 'Fine print'],
    ],
],

$formats  = Contenir\Contact\Format\Formats::fromConfig($config['contenir_contact']['format'] ?? []);
$renderer = new Contenir\Contact\Format\HtmlRenderer(Contenir\Contact\MapProvider::fromSettings($settings));

echo $renderer->render($office, $formats->get('footer'));
echo $renderer->render($business, $formats->chosen($block['fields']));   // a Contact block's format
bash
php bin/generate-vocabulary.php schemaorg-current-https.jsonld 30.2