Jump to content

Build Page Array for Predefined Tags of Images


kalimati
 Share

Recommended Posts

For a repeater field named "image_tags" in the "home" template, setting the tags list for an images field named "images"...

// Save repeater titles to images tags list
$pages->addHookAfter('saveReady', function(HookEvent $event) {
    $page = $event->arguments(0);
    // For the home template
    if($page->template == 'home') {
        // Get a string of tags from the repeater item titles
        $tags = $page->image_tags->implode(' ', 'title');
        // Get the images field
        $images_field = $this->fields->images;
        // Set the list of allowed tags
        $images_field->tagsList = $tags;
        // Save the field
        $images_field->save();
    }
});

The titles of the repeater items will need to abide by the rules for image tags, so no spaces allowed.

Quote

Tags may contain letters, digits, underscores or hyphens.

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...