20

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 many of those as they need, positioned together. From your template, when looping through blocks, you can check to see if the current block is the first/last of ...


17

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 mind, though, that in many cases this may make your CMS/data pretty dependent on a plugin.


15

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 to any field settings. This is how you access the headings of a table field Craft 2 {% set field = craft.fields.getFieldByHandle('myTableField') %} {% for ...


10

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 row in block.codePoints %} {# Assuming 'text' is the column handle of the text field #} <li>{{ row.text }}</li> {% endfor %} ...


7

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 of arrays: $tableData = array( array( "col1" => "data", "col2" => "data", ) ); // Then simply encode it when you set your field ...


7

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 }}</h3> {# Show the navigationHeadline if it has links #} <ul> {% for row in block.navigationLinks %} <li>{{ row....


6

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 more closely match what you're looking for: {% set myData = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %} {% for column in myData|batch(3, 'No item') %} <div ...


6

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 to manage and template. I posted an answer to a similar question with examples here.


6

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' => json_encode($tableData) )); However, the modifyImportRow documentation uses the (arguably better) method: // Set modified content $element->setContentFromPost(...


5

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. Although not as accessible when creating the entry, it seems like it would potentially be a lot easier to manage all around, with no limitations on filedtypes, ...


5

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, we're guaranteed that [0] will be set #} {% for column in entry.tableField[0] %} {% if column|length %} {% set reallyEmpty = false %} ...


4

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 with a little finesse, you might be able to do something like the following, using key, value in the for loop and twig's slice filter: <table> {% for ...


4

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.), so that's not old and left over column names you're seeing there. If you define custom handles in the Table field's settings, the cells' data will be ...


4

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. but also using the columns handle, e.g. row.price. If you don't want to use this feature or programatically loop the cells, don't define column handles!


4

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


3

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 Andre Elvan's brand new plugin Preparse Field. With that you would add a new field to you entry type that does some predefined Twig logic on every entry save. ...


3

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 entry.discography if row.releaseName %}


3

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 row {% endif %} {% endfor %} More information on the loop variable can be found in the twig docs.


3

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 in place of a table field.


3

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 provide a multidimensional array, which is what a table needs.


3

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 automatically decoded back into an array for you, you need to give your field type a defineContentAttribute() method that returns AttributeType::Mixed: public ...


3

Reverse it! <ul> {% for row in entry.myTableFieldHandle|reverse %} <li>{{ row.columnHandle }}</li> {% endfor %} </ul>


3

Basically you want to retrieve all entries where a certain field is not empty? Return entries where field is "not empty"


3

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 figure out how to prevent the form from sending a value even if the field was empty, therefore, I added a conditional to the template page which displays the ...


3

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.


3

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 theory and actually tried it on a table field I had laying around. This worked for me: {% set rows = shuffle(block.example) %} {% for row in rows | slice(0, ...


3

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", "two": "Option4" } ] This issue might be related to your feed however. In the dropdown, you have <altTitles> eg: - there should be a value from your ...


3

You can create a feed-me.php file under your /config directory, then you can configure the data delimiter: <?php return [ '*' => [ 'pluginName' => 'Feed Me', 'dataDelimiter' => '-|-', ] ]; On my side, that is not working all the time (if almost never), but the doc says it should! (https://verbb.io/craft-plugins/feed-...


2

Since there are a set number of quarters you can probably just collect the entries in a temporary array. Then use those to build your tables. {% set quarter1 = [] %} {% set quarter2 = [] %} {% set quarter3 = [] %} {% for row in entry.courses %} {% if row.classQuarter == 1 %} {% set quarter1 = quarter1|merge([row]) %} {% endif %} {% if ...


2

Maybe this is not the best idea for your exact use case, but what about using a Structure section for your entries with two levels. Top level entries would be your "actual entries" and their child entries would be a substitute for your current matrix blocks. In the template of top level entries you then collect the content of the children in sort order, ...


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