View Categories

Stampare i valori dei campi

I valori inseriti nei campi scelti nel file admin.php vengono stampati nel file site.php insieme al resto dell’HTML.

L’HTML viene stampato dalla funzione renderContent, esempio sotto.

public function renderContent()
{
$settings = $this->addon->settings;
ob_start(); ?>
<div class="container">

        <?php if ($this->includeTitle() != '' || $this->includeDescription() != '') { ?>
            <div class="row justify-content-center xbmb-5">
                <div class="col-md-6 text-center">
                    <?php
                    echo $this->includeTitle('heading3 xbmb-0 xbmt-0');
                    echo $this->includeDescription('text2 xbmt-4');
                    echo $this->includeStandardButtons('justify-content-center xbmt-4');
                    ?>
                </div>
            </div>
        <?php } ?>

    </div>
<?php
return ob_get_clean();
}

I valori dei 3 campi standard inclusi in ogni addon (titolo, descrizione e pulsanti) vengono stampati tramite funzioni apposite:

echo $this->includeTitle();
echo $this->includeDescription();
echo $this->includeStandardButtons();

Si possono passare delle classi da aggiungere all’elemento che sarĂ  mostrato specificandole da parametro:

echo $this->includeTitle('heading3 xbmb-0 xbmt-0');

Come stampare i campi non standard #

Facciamo finta di dover stampare i valori inseriti nei seguenti campi definiti nell’admin.php:

'items' => [
    'title' => Text::_('CTA'),
    'fields' => [

        'subtitle' => [
            'type'  => 'text',
            'title' => Text::_('Sottotitolo')
        ],

        'subtitle_selector' => [
            'type'   => 'headings',
            'title'  => Text::_('COM_SPPAGEBUILDER_ADDON_HEADINGS'),
            'desc'   => Text::_('COM_SPPAGEBUILDER_ADDON_HEADINGS_DESC'),
            'std'   => 'h3',
        ],
    ],
],

Un testo e un selettore di heading per, appunto, il testo.

Nel file site.php, stamperemo i valori dentro la funzione renderContent(), in questo modo:

public function renderContent()
{
$settings = $this->addon->settings;    

    ob_start(); ?>

    <div class="container">
        <div class="row align-items-center">

            <?php if ($this->includeTitle() != '' || $this->includeDescription() != '') { ?>

                <div class="col-md-6">
                    <?php
                    $subtitle_selector = isset($settings->subtitle_selector) ? $settings->subtitle_selector : 'h3';
                    echo ($settings->subtitle) ? '<'.$subtitle_selector.' class="heading5 htc-sub fw-700 xbmb-0">' . $settings->subtitle . '</'.$subtitle_selector.'>' : '';
                    ?>
                </div>

            <?php } ?>

        </div>
    </div>
<?php
return ob_get_clean();
}

$settings->subtitle_selector Stampa il selettore scelto da pagebuilder e $settings->subtitle stampa il testo inserito.

‘$settings’ dev’essere sempre incluso all’inizio di renderContent() in questo modo:

$settings = $this->addon->settings;

Serve a prendere tutti i dati dei campi inclusi nel file admin.php.

Torna in alto