dotnetic Posted October 11, 2018 Share Posted October 11, 2018 How do I add a class "uk-table" on the frontend to a FieldTypeTable? I am iterating through all elements from an admin template and eventually modify the values (for example concatenate the values of a Page field with a comma), but I don't know how to add the class to the table. The code that I am using right now is in a gist at https://gist.github.com/jmartsch/768d9dc19293528fe9ae82b7a8ee1c42#file-home-php In line 15 https://gist.github.com/jmartsch/768d9dc19293528fe9ae82b7a8ee1c42#file-home-php-L15 I tried to hook into the rendering, but as it is no Inputfield anymore, the hook does not work. Can someone help me please? Link to comment Share on other sites More sharing options...
dotnetic Posted October 11, 2018 Author Share Posted October 11, 2018 I found a way with str_replace, but I think this is not the best way. Here is what I added to my getFieldValue function: if ($fieldType == 'FieldtypeTable') { $value = str_replace('ft-table', 'uk-table', $value); return $value; } Suggestions, how I can do it better? Link to comment Share on other sites More sharing options...
bernhard Posted October 11, 2018 Share Posted October 11, 2018 $inputfield->addClass() does not work (you already have this line in the linked gist)? Or did you already solve it like this? Link to comment Share on other sites More sharing options...
dotnetic Posted October 11, 2018 Author Share Posted October 11, 2018 Sadly $inputfield->addClass() does not work. Link to comment Share on other sites More sharing options...
kongondo Posted October 11, 2018 Share Posted October 11, 2018 Try this: $inputfield->class .= ' your-classes';// @note the space Link to comment Share on other sites More sharing options...
OLSA Posted October 11, 2018 Share Posted October 11, 2018 Maybe this: https://gist.github.com/jmartsch/768d9dc19293528fe9ae82b7a8ee1c42#file-home-php-L35 change: if ($fieldType === "FieldtypeTable") { to: if ($fieldType === "FieldtypePageTable") { Link to comment Share on other sites More sharing options...
dotnetic Posted October 11, 2018 Author Share Posted October 11, 2018 @kongondo This also doesn't work. @OLSA This won't work because it is a FieldtypeTable and not a FieldtypePageTable, as you can see in the screenshot: Link to comment Share on other sites More sharing options...
bernhard Posted October 11, 2018 Share Posted October 11, 2018 Your screenshot shows an InputfieldTable, which is neither a FieldtypeTable nor a FieldtypePageTable ? Link to comment Share on other sites More sharing options...
Soma Posted October 11, 2018 Share Posted October 11, 2018 If you render the value of the field you get the table rendered by class TableRows. It's nothing to do with the Fieldtype or Inputfield render. So you can simply use the render function of the value == TableRows object and add your options. $value = $page->mytable->render(array("tableClass" => "uk-table")); Though nothing wrong with you str_replace. I don't get how that is bad but anyway. 4 Link to comment Share on other sites More sharing options...
dotnetic Posted October 11, 2018 Author Share Posted October 11, 2018 Thanks @Soma, this works fine. Maybe it is a solution for other fieldtypes I have too. Link to comment Share on other sites More sharing options...
Soma Posted October 11, 2018 Share Posted October 11, 2018 3 minutes ago, jmartsch said: Thanks @Soma, this works fine. Maybe it is a solution for other fieldtypes I have too. I don't know of any other Fieldtypes that work this way. 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