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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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' => ...
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. ...
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, ...
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 ...
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....
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. ...
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.
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?
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" =&...
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]....
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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>
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"
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 ...
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
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 ...
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",
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
table-field × 60templating × 14
matrix × 6
craft3 × 5
table × 5
plugin-development × 4
form × 4
custom-fieldtype × 4
custom-field × 4
field × 3
plugin-feedme × 3
forloop × 3
fieldtypes × 3
search × 2
conditional × 2
modules × 2
json × 2
import × 2
globals × 2
plugin-supertable × 2
drop-down × 2
csv × 2
entries × 1
plugins × 1
control-panel × 1