PHP code example of daandelange / clavisverbum

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

    

daandelange / clavisverbum example snippets


return [
    // Field names to hide from the preview columns
    'preview.hideFields' => false, // false | array
    // The label of a field preview. Template args: `field` and `language`. Global scope, can be overridden by blueprint
    'preview.label' => '{{ field.label }} / {{ language.code }}',
    // The label of a newly duplicated field. Template args: `field` and `language`. Global scope, can be overridden by blueprint
    'field.duplicationLabel' => '{{ field.label }} / {{ language.name }}',
];


$translatedStructure = $translatedStructureField->toTranslatedStructure();
// You can loop the data like this. As a Structure, it's a Kirby Collection.
foreach($translatedStructure as $item){
    // All calls below return a Kirby\Content\Field
    // Empty translations will fallback to the default language translation
    $item->normalfieldname();           // Non-translated value
    $item->mytranslatedfieldname();     // Translated in current lang
    
    $item->mytranslatedfieldname('en'); // explict english translation
    $item->mytranslatedfieldname_en();  // explict english translation (alt)
}

// Or use the data as an array :
$data = $translatedStructure->toArray();

// There's also a way to loop your data fields as defined in the blueprint
$untranslatedFields = $translatedStructure->getTransatedFields(); // Retuns array
foreach($translatedStructure->getTransatedFields() as $id => $field){
    echo(\Kirby\Cms\Html::a('./tags/'.$id, $field['label']));
}


// Returns a TaxonomyStructure
// Which also is a TranslatedStructure (see usage above)
$taxonomy = $field->toTaxonomyStructure();

// Extra TaxonomyStructure features
$options = $taxonomy->toTags(); // All structure items as a rendered Options array

$tags = ['hello', 'world']; // <-- typically $tagsField->split()
$selection = $taxonomy->toTags($tags); // Selected structure items as a rendered Options array

// The tagsbinding generated from your fields
$tagsbinding = $taxonomy->getTagsBinding(); // Array with field->tag mappings
// It's an array with Options keys and KQL strings with the target value.
// Available arguments: `structureItem`.
$tagsbinding = [
    'value' => '{{ structureItem.id }}',
    'text' => '{{ structureItem.name }}',
    'info' => '{{ structureItem.description }}',
    'icon' => 'tag',
];
$selection = $taxonomy->toTags($tags, $tagsbinding); // Usage with a custom binding


foreach($field->toTaxonomyTags() as $entry){
    
}