Skip to main content

Questions tagged [matrix]

Matrix fields allow you to create multiple blocks of content within a single field.

Filter by
Sorted by
Tagged with
16 votes
2 answers
5k views

How to save Matrix data programmatically in Craft 3

How can you programmatically save an entry that has a Matrix field in Craft 3? (Something like this gist for Craft 2)
Brandon Kelly's user avatar
11 votes
1 answer
3k views

Matrix field input error from within the control panel

I have a matrix field with around 26 block types with between 2-6 fields on each. It seems like I've hit a limit and cannot add any more fields to any of the block types. I can add a field if i delete ...
Matthew Woods's user avatar
18 votes
6 answers
6k views

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

I was wondering if anyone has stumbled on a good solution for including matrix-like fields within a matrix block. I’m working on a site where each page's is constructed in one big matrix with several ...
philzelnar's user avatar
16 votes
1 answer
3k views

How to get matrix editor into frontend?

I've currently setup a matrix-field for adresses. I added the field as required field to my user-group "Customer". Which breaks the registration, as a user can only be registered, when the matrix has ...
Andre Mohren's user avatar
13 votes
5 answers
7k views

Image transforms returning cpresources url

I'm trying to get Craft to render an image transform defined in the control panel. No image is added to the "filelocation/_transformhandle" folder and returns the url "/cpresources/transforms/98" ...
FrankFlitton's user avatar
31 votes
4 answers
21k views

Test for empty field?

How do I check if a field is blank? I thought it was something like {% if article.articleImage is defined %} Which in this case is testing an Assets field (and seems to work). Tried the same for a ...
pumkincreative's user avatar
5 votes
2 answers
2k views

How to save a matrix content of a new entry in my plugin?

I have a section of type channel with a matrix field. I want to know how I would save the matrix content while I save the entry as well. I know I can save the entry as follows: $entry = new ...
Moin Qidwai's user avatar
10 votes
2 answers
3k views

Matrix fields within matrix field

Is there a way to place matrix fields inside of matrix fields or also to setup a matrix field with existing fields? We are currently trying not to have duplicate content in terms of fields, but that ...
nexflo's user avatar
  • 539
4 votes
2 answers
1k views

Identify immediate siblings block type in matrix

I have a type of content that i use on the homepage of a site I am building, the code is shown here: <ul> {% for point in entry.keyPoints %} <li> <div class="a-...
Christopher Healey's user avatar
11 votes
2 answers
1k views

Search matrix for blocks with upcoming dates

I have a matrix field with one "event" block type that contains several fields. One of those fields is a date field. Is there a way to get just blocks with upcoming dates?
André Elvan's user avatar
  • 7,288
7 votes
3 answers
2k views

Getting all content, including Matrix fields from an EntryModel

Initially I was doing $entry->getContent()->getAttributes(), but noticed my Matrix fields were all null. What is the right way to do this? I see that $entry->myMatrixField gives me the ...
Tim Kelty's user avatar
  • 3,081
3 votes
1 answer
688 views

Query for blocks across Block Types using the new field parameter?

This is a great new feature of Craft 2.3: It is now possible to set custom field parameters on Matrix block queries. I was wondering what would happen, if two or more Matrix Block Types had a ...
carlcs's user avatar
  • 36.3k
9 votes
1 answer
2k views

How to iterate over matrix field from a plugin

I'm writing a plugin where I have the id of an entry, that entry has a matrix field, and I want to iterate over the blocks of the matrix field. In php. How do I do that? Pointers to good documentation ...
Marion Newlevant's user avatar
8 votes
1 answer
1k views

How to update Matrix field on frontend for user profile

I have used the following code to allow our users to update their own profile. Everything works fine apart from not being able to update existing Matrix entries. New Matrix field entries work fine. ...
GlennJ's user avatar
  • 575
6 votes
1 answer
688 views

How can I return specific matrix rows based on criteria?

So let's say I have the following code. I have the data to retrieve the entry I want, But I only want to return some of the matrix rows based on some criteria. Example Code: {% set entryId = 1 %} {% ...
nfourtythree's user avatar
5 votes
2 answers
1k views

How to retrieve entries from two entry-types ordered by different date-fields?

I have two entry-types, 'Events' and 'Reports'. 'Events' have a matrix-field ('eventMultiDate') that allows authors to assign multiple dates to an event (recurring). 'Reports' have the default '...
Clemens Sum's user avatar
4 votes
1 answer
969 views

Group by Field in Matrix Field

Is it possible to group by a field within a matrix field. I have a channel of players which holds their details. I have a structure for teams which includes a matrix field for a Player. The Player ...
mmc501's user avatar
  • 1,789
3 votes
1 answer
2k views

Show a table field's column headers in template?

The question says it all. I have: A Matrix field, with A subfield with the type table Two columns within that table of which I want to show the column headers in my template Is that possible and if ...
Paul's user avatar
  • 6,338
3 votes
1 answer
1k views

Duplicating Matrix fields with content from another locale

I'm working on an Element Action that will duplicate some fields from the primary locale, to whatever locale the user is currently in, if those fields are already empty. Asset fields seem to work ...
Mike Pepper's user avatar
  • 4,391
3 votes
1 answer
1k views

Managing Frontend JS for Matrix Fields

What is the best course of action to allow the creation/deletion of matrix fields in front-end. For context this in a Commerce Order Field. JS is mess right now, any underlying Craft JS libraries I ...
Dale Inverarity's user avatar
2 votes
1 answer
641 views

How to get all images from entries including Matrix field

I have a photo gallery that pulls in all entries and then finds the images within them and then displays them along with links to the entries that used that image. Except, it's not pulling in the ones ...
Paul Frost's user avatar
  • 1,060
2 votes
1 answer
235 views

Missing Matrix row types on output after upgrade to Craft 3 (subsetting and cloning ElementQueries)

Update: Now I know the cause of my problem, I have appended to the original question title to try and help other people stumbling across the same issue. I have a pending support ticket open with P&...
Jonathan Schofield's user avatar
1 vote
3 answers
978 views

Find entries that use a specific block in their Matrix field?

Suppose a Mtrix field named MyMatrixField has three blocks called Text, Images, and Buttons. What MySQL query would list the section and title for all entries whose MyMatrixField field has a Buttons ...
Sandwich's user avatar
  • 636
1 vote
1 answer
468 views

Find entries that have a category selected from a category field within a matrix block

I've got a Section that uses a Matrix field, that has a block, that has a categories field in it. I want to find all entries using this Matrix field, who has a categories field and has a certain ...
John's user avatar
  • 974
1 vote
1 answer
1k views

How do I get the column headers of a table in a matrix?

I'm trying to write a general purpose matrix template and I've come up on a little snag with tables fields. I see no way to get the column header values. The answer here mentions craft.fields....
Bill Criswell's user avatar
0 votes
1 answer
737 views

Categories Related To Matrix Fields

Please help me build my sandwich locator maker :) I have 3 categories, breads, meats, condiments I have a Section called subShops with a matrix field. My matrix field is called sandwichBuilder, ...
Vin's user avatar
  • 383
11 votes
2 answers
3k views

Can I get an entry by Matrix Block ID?

For a url like domain.com/example/123 where 123 is a Matrix Block ID (not an Entry ID), can I get the associated entry for given block ID in a template? Or, for a more general approach, what would be ...
Low's user avatar
  • 537
6 votes
3 answers
3k views

Output matrix field data

I have a matrix field with a block called "employment", under this block are fields, one of those fields is a drop down. I'd like to be able to output the drop down field as a select list so users ...
Matt V's user avatar
  • 491
6 votes
1 answer
545 views

How can I display related entries selected within a Matrix field?

Consider an employee listing... I have 2 sections: 1 for companies, 1 for personnel. In the personnel section, there is a matrix field within which one field is a relational one to relate the staff ...
V. Arora's user avatar
5 votes
1 answer
2k views

Return Matrix Field block number

Just wondering if there's a way to return the matrix block number during the loop? For example: {% for block in entry.myMatrixField %} {% if block.type == "quote" %} <blockquote class="...
Mark Notton's user avatar
  • 2,337
5 votes
1 answer
1k views

Save matrix block to new entry in plugin

I have been trying two separate methods to accomplish and both keep resulting in the same errors no matter what I try. The entry I am saving has a few fields the last of which is a matrix block (I am ...
Panda4Man's user avatar
  • 253
5 votes
3 answers
2k views

How do I get Matrix elements to copy their content across language Locales?

I returned to a site designed months ago, and added a second language to it. From the beginning, this site had prominent composition of entries out of multiple elements in their matrix, with ...
narration_sd's user avatar
  • 1,707
4 votes
2 answers
1k views

Inserting Relationship Into Entries Field - Plugin Not Saving Relation

I was hoping someone could shed some light on this issue I'm having. I'm trying to update a relationship field through a plugin, without much success, the entry looks like this: I saw a post on here ...
Alec Ritson's user avatar
  • 4,539
4 votes
1 answer
409 views

How can I iterate more than 100 blocks in a matrix field for loop?

I am looping through a matrix field and it appears to stop looping when the index reaches 100 but I have more than 100 blocks here. How can I loop through the remaining blocks? {% for block in entry....
user243's user avatar
  • 161
4 votes
1 answer
460 views

Setup default Matrix blocks and default values for sub-fields?

Question is what table can't achieve, can be achieve by matrix but problem is matrix cannot have default row value like table have. Anyway to achieve it? Thanks.
Hs Tung's user avatar
  • 367
4 votes
2 answers
1k views

How to query with relatedTo of a Relationship Field in a Matrix Field block

I have structures called Instrument and Person. On the person structure, I have a Matrix field called Roles. Roles has a block called Musician. And That block type has a Relationship Field called ...
Bill Columbia's user avatar
4 votes
1 answer
1k views

How do I retain form input values after submitting error-ridden form containing matrix field inputs

I'm looking for a way to keep matrix inputs populated with their original value after submitting a form containing errors. I'm already aware of the method of doing this for general inputs as shown ...
ntoombs19's user avatar
3 votes
1 answer
378 views

Updating matrix field from font-end with $entry->setFieldValue() pulls in Cp bundle on save

I have an entry with a matrix field which I'm updating from front-end. The update works fine, but when the (font-end) page reloads after submitting the form, the CP bundle assets get included (...
ijust's user avatar
  • 163
3 votes
1 answer
1k views

Get related entries from matrix field

I have a matrix field with one block type. In that block type, I have one field that is a related entries field. How do I access the title from the related entries field from the matrix field? Here ...
user3818623's user avatar
3 votes
1 answer
405 views

How can I repopulate a matrix field on a front-end form?

I have a matrix field on my front-end form. Everything is working properly, data is saved correctly etc. I am testing & trying to break things and I noticed I wasn't repopulating those fields if ...
Damon's user avatar
  • 4,706
3 votes
1 answer
831 views

Nesting level too deep when looping through matrix blocks

I'm running into a nesting level error when looping through matrix blocks, and I can't quite figure out what the problem is. The problem arises when I use a variable to track the type of the previous ...
Nick F's user avatar
  • 1,215
3 votes
1 answer
699 views

Filtering Matrix through field value and multiple relations

I've the following situation: Accommodations (entry) title description (textfield) ... linkedTo (matrix block) Sport (category) targetGroup (category) minimumAge (number) maximumAge (number) What ...
Jaco's user avatar
  • 33
3 votes
2 answers
739 views

How do I select entries that have a particular block type?

Say I have a channel with a matrix field which has two block types - text and video. Is there any way to select all entries in that channel that have a video block? Idea 1 Use the Low Blocks plugin ...
Jamie Pittock's user avatar
2 votes
2 answers
931 views

Creating a matrix entry with a plugin

I'm working on a plugin to save user profile data. I have a matrix field called addressMatrix, I've made address a matrix because users can save multiple addresses. Every address entry will have the ...
Matt V's user avatar
  • 491
2 votes
1 answer
2k views

How can I tell if a field exists in a block of a matrix?

I want to see if a certain field exists in a block of a matrix. Here is my code. {% for block in entry.someStepContainer %} <div class="each-step"> {% if block.type == "someStep" %} ...
Nick's user avatar
  • 217
2 votes
1 answer
308 views

How do I group matrix blocks into batches of 4?

I am building a site which uses one content type as its primary holder for content. This is to make content editing easier on the content editor. All URL's are primarily accessing this one content ...
lucaslink's user avatar
2 votes
1 answer
423 views

Is it possible to share a field between Matrix Blocks?

I'm attempting to do some advanced layout orchestration using Matrix blocks. I'll need different blocks types – Image, Quote, Body – that can be combined, but they'll each need to share a few fields ...
cmal's user avatar
  • 815
2 votes
1 answer
580 views

Issue with Matrix `type` property and Live Preview?

I have problems getting Live Preview to work with this Twig code that gets data from a Matrix field. {{ entry.matrixField.type('copy').nth(0).plainText }} As soon as I remove the type property from ...
carlcs's user avatar
  • 36.3k
2 votes
2 answers
534 views

Only execute twig block if a Matrix radio has a certain value

I have a scenario where I'm using a Matrix to store and output 'sponsored links' for a page. Each link also has a radio button to select whether to display in a left hand column or a right hand column ...
Matt Wilcox's user avatar
  • 3,209
2 votes
2 answers
623 views

Element Query matrixfields where

I'm trying to query entries in a section where the (activities) entry has an item in a matrix field timeSlots -> timeSlot -> startDate. The startDate must be >= NOW(). $query = Entry::find()->...
Jeroen's user avatar
  • 308