Jump to content

[SOLVED] Show icon in FieldtypeOptions


gregory
 Share

Recommended Posts

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

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

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

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

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 by kongondo
  • Like 1
Link to comment
Share on other sites

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...