PascalKonings Posted October 11, 2021 Posted October 11, 2021 Hi, I'm building a picture gallery, consisting of multiple pages. On each page I would like to add tags to my images, which I can do nicely using the predefined image tags I can set up. However, I was wondering if it is somehow possible to fill the predefined image tags with more dynamic values, like for instance a list of pages (using title or a different field of that page, adhering to the rules for tags). This would make it more flexible for me, as I would not have to have multiple different images fields with different sets of predefined tags.
Zeka Posted October 11, 2021 Posted October 11, 2021 Hi @PascalKonings You can use page refference field by implementing custom fields for you image field https://processwire.com/blog/posts/pw-3.0.142/ 2
PascalKonings Posted October 11, 2021 Author Posted October 11, 2021 28 minutes ago, Zeka said: Hi @PascalKonings You can use page refference field by implementing custom fields for you image field https://processwire.com/blog/posts/pw-3.0.142/ Wow, awesome! Thanks Zeka, will check this out!
Robin S Posted October 12, 2021 Posted October 12, 2021 @PascalKonings, the suggestion from @Zeka is probably the way to go, but in case you do want to stick with image tags you can set them dynamically in a hook in /site/ready.php: // Dynamically set the selectable tags for an images field $wire->addHookAfter('InputfieldImage::renderReadyHook', function(HookEvent $event) { /** @var InputfieldImage $inputfield */ $inputfield = $event->object; // The images field $field = $inputfield->hasField; // The page that the field is on $page = $inputfield->hasPage; // Only for a specific images field if(!$field || $field->name !== 'your_image_field') return; $config = $event->wire()->config; $js_name = "InputfieldFileTags_$field->name"; $data = $config->js($js_name); // Set the tags however you like, using $page if needed $data['tags'] = [ 'carrot', 'pumpkin', 'cauliflower', ]; $config->js($js_name, $data); }); 3
PascalKonings Posted October 13, 2021 Author Posted October 13, 2021 10 hours ago, Robin S said: @PascalKonings, the suggestion from @Zeka is probably the way to go, but in case you do want to stick with image tags you can set them dynamically in a hook in /site/ready.php: // Dynamically set the selectable tags for an images field $wire->addHookAfter('InputfieldImage::renderReadyHook', function(HookEvent $event) { /** @var InputfieldImage $inputfield */ $inputfield = $event->object; // The images field $field = $inputfield->hasField; // The page that the field is on $page = $inputfield->hasPage; // Only for a specific images field if(!$field || $field->name !== 'your_image_field') return; $config = $event->wire()->config; $js_name = "InputfieldFileTags_$field->name"; $data = $config->js($js_name); // Set the tags however you like, using $page if needed $data['tags'] = [ 'carrot', 'pumpkin', 'cauliflower', ]; $config->js($js_name, $data); }); Thanks!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now