Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.
20 votes

Solution for Matrix-within-Matrix (or More Robust Table Fields)

Rather than trying to store multiple stats together in a single block, another option would be to make a "Stat" (singular) block type, which only holds a single stat, and just have authors create as ...
user avatar
18 votes
Accepted

Show a table field's column headers in template?

You don't get table headings with the entry model data (use the dump() function while in dev mode to see yourself). But there's the method getFieldByHandle() that returns a field model containing info ...
user avatar
  • 35.8k
17 votes

Solution for Matrix-within-Matrix (or More Robust Table Fields)

Folks may also want to checkin the Super Table plugin that just came out. It allows you to create table fields that include almost any field type: https://github.com/engram-design/SuperTable Keep in ...
user avatar
10 votes
Accepted

How to correctly output a Table Field?

I suppose in your example codePoints is the actual Table field. In order to output the table rows, the template should look like this: {% if block.codePoints | length %} <ul> {% for ...
user avatar
  • 611
7 votes
Accepted

Inserting data into a table fieldtype via plugin?

The thing to keep in mind here is that a table field contains a simple JSON string. So you can (and should) use PHP's native json_encode function to prepare your data... // Your data will be an array ...
user avatar
  • 23.6k
7 votes
Accepted

Accessing a Matrix field in a Global

Not sure why you're referencing "entry" in your code, I'd think the code should be: {% for block in footer.links %} {% if block.navigationLinks | length %} <h3>{{ block.navigationHeadline ...
user avatar
  • 7,228
7 votes

Evenly dividing up table items in columns

It's actually quite simple! What you're looking for is Twig's batch filter... Ironically, the example given on that page is nearly identical to what you are requesting. I've adapted the example to ...
user avatar
  • 23.6k
6 votes

Solution for Matrix-within-Matrix (or More Robust Table Fields)

This question was asked prior to the release of the Neo plugin/field type. I think this would offer a better approach than the SuperTable (which was/is still awesome), just because I think it's easier ...
user avatar
6 votes
Accepted

Why won't the Import plugin accept this JSON string?

You're close! The method that Lindsey recommends should work with the following method of adding content to a field: $entry->getContent()->setAttributes(array( 'tableFieldHandle' => ...
user avatar
5 votes

Solution for Matrix-within-Matrix (or More Robust Table Fields)

An alternate solution that might work is to create separate channels for 'stats' and 'quotes', and then use an entries field within your matrix block to add them to the 'stats' and 'quotes' blocks. ...
user avatar
5 votes

Check if a table field’s row has a value

Something like this should do what you're looking for and will work for any number of rows: {% set reallyEmpty = true %} {% if entry.tableField | length %} {# Since you've got a default row set, ...
user avatar
  • 66.4k
4 votes
Accepted

Double storage of values in table-field

The data is not stored twice in the database. I suspect that craft adds the additional array items when prepping the data, so that they can be referenced by either column number or column title. But ...
user avatar
4 votes
Accepted

Is there a way to purge old data in a table?

Your interpretation of why you're getting duplicate columns when looping your your table field is wrong. Each column is always accessible via a automatically generated column handle (col1, col2, etc....
user avatar
  • 35.8k
4 votes

How to correctly output a Table Field?

Craft adds those extra elements to each array of table cells only if there's column handles defined in your Table Field. This allows you to not only access a cell's value via row.col1, row.col2, etc. ...
user avatar
  • 35.8k
4 votes
Accepted

Table fields, default single empty row, and never returning as empty?

You could test if the first cell is empty {% if entry.whiskeyTableHandle|length and entry.whiskeyTableHandle[0][0] %} {% endif %} Or you simply remove all default rows in the field’s settings.
user avatar
  • 35.8k
4 votes
Accepted

Adding Columns to a table

With the supercool table maker you can create dynamic tables. Is this what you are looking for?
user avatar
4 votes

How to set field values for the table field type in Craft 3

I figured this out. The table field is expecting JSON: $entry = new Entry(); $entry->sectionId = 1; $entry->typeId = 1; $entry->title = $title; $entry->setFieldValues([ "field_handle" =&...
user avatar
3 votes

Check if a table field’s row has a value

You can do something like this: {% if entry.tableField|length and ( entry.tableField[0].columnHandleOne or entry.tableField[0].columnHandleTwo or entry.tableField[0]....
user avatar
3 votes

How do I query for entries, based on a value inside a table?

Craft saves all the table's data serialized to a single cell in the database, so there's not really a good way to set query conditions to match something in a table field. What you could do is to use ...
user avatar
  • 35.8k
3 votes
Accepted

How do you not output table field if there are no values?

When you define a table field, it comes with one row by default. I'm not sure why this is. You can remove this row by clicking on the - icon: To filter out those rows in twig, try: {% for row in ...
user avatar
3 votes

Get last row in table field for loop

In any for loop you can use the loop variable that twig gives you. For example: {% for row in myTable %} {% if loop.last %} This is the last row {% else %} This is anything but the last ...
user avatar
  • 2,301
3 votes

Can a Table Column be Rich Text / WYSIWYG?

I think that's actually a table field type you are referring to, not a Matrix Field Type. Matrix field types can indeed have Rich Text. There are a lot of instances where a Matrix field can be used ...
user avatar
  • 1,818
3 votes
Accepted

Saving to Table Field Type via Plugin

NOT TESTED I think you can just add an array to gistDistribution, it will get json_encoded before saving. I think you'd have to set the variable like this: $arr[0] = array(...); That way, you ...
user avatar
  • 6,288
3 votes
Accepted

Why won't the values of an editableTableField show up in my template?

That string that Craft stores is just JSON. When you try to save an array, Craft will automatically JSON-encode it, since MySQL doesn’t have an array-based data type. To get that string to be ...
user avatar
3 votes
Accepted

How to reverse the rows in a table?

Reverse it! <ul> {% for row in entry.myTableFieldHandle|reverse %} <li>{{ row.columnHandle }}</li> {% endfor %} </ul>
user avatar
  • 66.4k
3 votes
Accepted

Show a quote on my login page

Basically you want to retrieve all entries where a certain field is not empty? Return entries where field is "not empty"
user avatar
3 votes
Accepted

How do I prevent empty table rows from being created when a front end form is submitted?

I figured out a solution. When I looked in the database I could see {"col1":"","col2":""} in the content even though the user didn't enter any content in the front end text form field. I couldn't ...
user avatar
  • 836
3 votes
Accepted

Creating a editable table with Element Select in column

For my specific case, Super Table was the answer. You can also check Neo
user avatar
3 votes
Accepted

Limit rows using Table

I have never tried it on a table field, but you could try: {% for row in block.example.limit('1').order('RAND()') %} {{ row.examplerow }} {% endfor %} OK, above will not work. I went back on my ...
user avatar
  • 1,517
3 votes
Accepted

Feed Me: How to format JSON for a table field?

You can do this a number of ways, and essentially just need an array-like structure to represent the rows. "Table": [ { "one": "Option1", "two": "Option2" }, { "one": "Option3", ...
user avatar
  • 3,392

Only top scored, non community-wiki answers of a minimum length are eligible