gregory Posted October 2, 2020 Share Posted October 2, 2020 Hi Guys, is it possible to retrieve the icon of a field set in FieldtypeOptions? Eg, setting a "WiFi" icon to a "WiFi" field (checkbox) in the admin, and then show this icon + name on frontend? // Output multiple selection: foreach($servizi as $item) { echo '<ul class="uk-list">'; echo '<li>' . $item->title . '</li>'; echo '</ul>'; } Thank You in advance. Link to comment Share on other sites More sharing options...
kongondo Posted October 2, 2020 Share Posted October 2, 2020 I'm not sure if you mean a ProcessWire field icon that can be set in the Advanced Tab when editing a field? If yes: $f = $fields->get('name_of_field_with_the_icon'); $icon = $f ? $f->icon : ''; Link to comment Share on other sites More sharing options...
gregory Posted October 2, 2020 Author Share Posted October 2, 2020 Thanks for the reply, but that's not what I need. The backend it's ok, but in frontend I would like to show the icons. I attach two screenshots. Link to comment Share on other sites More sharing options...
dragan Posted October 2, 2020 Share Posted October 2, 2020 I guess it would be easier if you'd use PageReference instead of FieldtypeOptions. Then you could create your own "servizi" template with an image field that hold the icon (limit to one single image), and then it would be a breeze to just output $item->icon->url etc. Link to comment Share on other sites More sharing options...
kongondo Posted October 3, 2020 Share Posted October 3, 2020 12 hours ago, gregory said: The backend it's ok, but in frontend I would like to show the icons. I see. However, I still don't get where the icons are coming from. For instance, where have you stored your wifi icon? Where is the icon for Piscina? Etc..Unless it is a new feature I am not aware of, FieldtypeOptions doesn't store icons. Link to comment Share on other sites More sharing options...
gregory Posted October 3, 2020 Author Share Posted October 3, 2020 1 hour ago, kongondo said: I see. However, I still don't get where the icons are coming from. For instance, where have you stored your wifi icon? Where is the icon for Piscina? Etc..Unless it is a new feature I am not aware of, FieldtypeOptions doesn't store icons. Unfortunately the icons are not stored anywhere. I'll see what I can do with PageReference... ? Link to comment Share on other sites More sharing options...
kongondo Posted October 3, 2020 Share Posted October 3, 2020 (edited) 20 minutes ago, gregory said: I'll see what I can do with PageReference... ? Yes. This will be more versatile. Alternatively, if you were working with a known set of icons that won't change or wont' change much, you could use the separate value|title feature of FieldtypeOptions. Quote Separate Option Values By default only titles are kept with each option. If you want to maintain a separate value and title, enter your option in the format value|title (for new options) or 123=value|title (for existing options that already have an ID assigned). The text for value and title will be kept as separate $option->value and $option->title properties from the API. These properties can also be independently queried to find pages from the API. Looks a bit hacky but you could do something like this (assuming you are using font awesome): fa-coffee|Breakfast fa-cutlery|Ristorante fa-bed|Bed fa-wifi|Wifi fa-car|Car Park fa-wheelchair| Accessibility // OR... coffee|Breakfast cutlery|Ristorante bed|Bed wifi|Wifi car|Car Park wheelchair| Accessibility You would then be able to access the icons names using $item->value. Obviously this means it is only the developer who will be able to determine and set icons (which may not be a bad thing actually). Just a thought... Edited October 3, 2020 by kongondo 1 Link to comment Share on other sites More sharing options...
gregory Posted October 3, 2020 Author Share Posted October 3, 2020 36 minutes ago, kongondo said: Alternatively, if you were working with a known set of icons that won't change or wont' change much, you could use the separate value|title feature of FieldtypeOptions. Great! That's exactly what I was looking for. It works perfectly! Thanks a lot ? Link to comment Share on other sites More sharing options...
kongondo Posted October 3, 2020 Share Posted October 3, 2020 Excellent! Glad you got it sorted. ? 1 Link to comment Share on other sites More sharing options...
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