Jump to content

[SOLVED] Add class to FieldtypeTable before outputting it


dotnetic
 Share

Recommended Posts

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

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

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.

  • Like 4
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...