Verwendung: Option Callback Wert ausgeben

info's Avatar

info

04 Nov, 2021 05:38 PM

Produkt: Custom Elements Contao

Ich stehe gerade auf dem Schlauch und die Antwort ist sicher mega einfach...
Wie kann ich aus einer Liste den Wert statt dem Label ausgeben?

'person' => array(
    'label' => array('Person auswählen', ''),
    'inputType' => 'select',
    'default' => '',
    'options_callback' => function() {
        return array(
            '123'   => 'Max Mustermann',
            '543'   => 'Frauke Müller',
            '232'   => 'Sigmund Freud',
            '133'   => 'Dalai Lama',
        );
    },
    'eval' => array('tl_class' => 'clr w50'),
),

Template
<?= $this->person ?> gibt mir immer nur das Label aus - also 123 oder 543

Vielen Dank für Eure Hilfe.

  1. Support Staff 1 Posted by RockSolid Theme... on 05 Nov, 2021 10:29 AM

    RockSolid Themes's Avatar

    Vielen Dank für Ihre Frage.

    Dazu können Sie entweder das Array des Callbacks verändern:

    return array(
        'Max Mustermann',
        'Frauke Müller',
        'Sigmund Freud',
        'Dalai Lama',
    );
    

    Oder alternativ die Zuordnung der Werte zur Bezeichnung im Template vornehmen:

    <?php
        $persons = array(
            '123' => 'Max Mustermann',
            '543' => 'Frauke Müller',
            '232' => 'Sigmund Freud',
        );
    ?>
    …
    <?= $persons[$this->person] ?>
    

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac