Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Questions tagged [matrix]

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

Filter by
Sorted by
Tagged with
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
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
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
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
14 votes
2 answers
2k views

How can I return data from a Matrix field in random order?

I have a slideshow with slide data managed in a Matrix field. How would I go about randomizing the data returned in the template so the slides show in a different order on each page load?
Anna_MediaGirl'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
11 votes
3 answers
2k views

Programatically create a Matrix field

I'm developing a plugin which requires certain sections and fields to exist so I'm currently creating them in the onAfterInstall() method of the plugin. I can create individual fields, sections, ...
Anthony's user avatar
  • 375
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
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
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
10 votes
3 answers
8k views

Check to See if Field Exists

When looping through a matrix, is there aquick way to check whether or not the block has a particular field (not if the field is empty, but if the field exists at all). I have a matrix with ~20 block ...
philzelnar'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
9 votes
2 answers
1k views

Is it possible to output the name of a Matrix Block?

I'd like to output the Names of Matrix Blocks. I know you can filter by block types e.g. {% for block in entry.myMatrixField.type('text, heading') %} {% if block.type == "heading" %} <h3>{{ ...
Natetronn's user avatar
  • 1,375
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
2 answers
4k views

How do you filter matrix blocks by type?

Is there a way to filter a matrix by block type, or get a count of how many items there are of a certain type? Can't find a syntax example. I created a matrix with two blocks. In pseudo code, ...
idahotallpaul's user avatar
8 votes
1 answer
876 views

How Can I Include a Conditional for First Type of Matrix

I want to include a conditional for when the 'Text' block type is returned for the first time in a loop. In css it would be first-of-type. Here's what I have at the moment: {% if type == 'text' and ...
Niall Thompson'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
7 votes
4 answers
4k views

Templating Matrix Block

It's my first website using Craft. I'm trying to figure out how to loop Matrix. I have created a field called bannerMatrix with a block type called banner that has 3 fields: Image (assets) Heading (...
Sylvia Prabudy's user avatar
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
7 votes
4 answers
1k views

Matrix field alternative (or easier field grouping)

Just started working with Craft, and it's been great! One question I have is regarding the 'correct' way to create a group of fields, rather than using Matrix or Table. To better illustrate, see the ...
crawf's user avatar
  • 3,562
7 votes
3 answers
381 views

Create matrix block with no fields

Is it possible to create a matrix block with no fields? I'm using matrix as a page builder and have several scenarios where certain matrix blocks simply act as true/false checks. As an example, my ...
Joe B's user avatar
  • 146
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
4 answers
4k views

What's the most user friendly way to create a video block in a matrix field?

I want to make it super easy for my user to embed a video from YouTube (maybe eventually from other sources) without having to get the iframe code. They should only have to enter the URL for the video,...
Katie Fritz's user avatar
6 votes
2 answers
753 views

Possible have matrix rows collapsed by default in the Control Panel?

Is it possible to have all Matrix rows in the Control Panel entry be in the collapsed state by default? Thanks. Lori
Lori's user avatar
  • 866
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
6 votes
1 answer
413 views

Return entry where matrix field is not empty

I am trying to get a random entry which has the quote matrix field populated. I've tried this: {% set entry = craft.entries.section('entries').quote(':notempty:').order('RAND()').limit(1) %} That ...
Katrin's user avatar
  • 674
6 votes
1 answer
903 views

Eager Load Matrix Field with Assets Field Type

I am trying to eager load an image asset assigned to a matrix. The template is pulling entries in from a section and each entry has the matrix field assigned to it that serves as an image gallery. ...
triplethreat23's user avatar
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
4 answers
2k views

How to order by matrix field?

I have a section where its entries have a matrix field (matrixField). In the first matrix block there is a date field (dateField). I want to get my entries ordered by that date field. Is this possible?...
Lars Bilke's user avatar
5 votes
2 answers
2k views

Is there a maximum number of fields in a single matrix?

I have a matrix with around 75 fields in it. They are spread over multiple "Block Types". When I create a new field and save the matrix, the new fields aren't being saved. Even worse, when I create ...
chrisyour's user avatar
5 votes
1 answer
2k views

How to: Flexible Twig Templates in Craft

I am just starting out with Craft CMS. What I see right now is a lot of static content in the html templates. Even in the demo. {% block content %} <h1>{{ entry.title }}</h1> {{ entry....
Jon Riel's user avatar
  • 151
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
5 votes
2 answers
460 views

Is there a way to populate a drop-down with the templates files in a folder?

When I have a folder setup for template partials, is there a way I could automatically populate a drop-down with the list of templates in that folder? This would be useful in the case where I have a ...
Steve Adams's user avatar
  • 1,671
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
5 votes
2 answers
2k views

Reusable Matrix block types

I'm building a site that makes heavy use of the Matrix field, which overall has been great. The one problem I'm running into is that I find myself duplicating a lot of Matrix blocks. To use the ...
aw04's user avatar
  • 185
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
3 answers
3k views

Search for entries with matrix field's value

I'm building a travel site containing Campaigns (entries) Each of these campaigns has multiple travel dates, modelled by a matrix field of [startDate, endDate, price] I want to do the following ...
thoaionline's user avatar
5 votes
1 answer
2k views

Accessing a Matrix field in a Global

I have created a Global with the handle 'footer', which contains a Matrix field 'links' and I'm trying to get this into a template, but I can't seem to get this to work. The 'links' Matrix contains a ...
doubleplusgood's user avatar
5 votes
1 answer
2k views

How to check if matrix block type is empty or not

I have a matrix field with two different block types and I want create a conditional to check if one of the blocks is not empty show it and if it is show the other. This is not working: {% for block ...
fodney's user avatar
  • 193
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
5 votes
1 answer
92 views

Matrix: Hide preview

Is it possible to hide the preview shown by default when Matrix blocks are collapsed? You can collapse Matrix blocks by clicking the “Collapse” menu option, or by double-clicking on a block’s ...
Ian Young's user avatar
  • 584
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
1 answer
855 views

Saving big matrix fields problems

I'm implementing a site with just one very big matrix field called 'blocks', and all my frontend is designed with BEM CSS with a lot of components. But i'm facing problems with this big field. 1) If ...
gabrielmoreira's user avatar
5 votes
1 answer
430 views

Is there a way to hide Matrix blocks based on the Selected Entry Type?

I have 2 primary entry types, one for a full width page, and one for a sidebar page. The sidebar page shares about 90% of the same block types as the full width page. The other 10% do not apply to ...
Steve Adams's user avatar
  • 1,671
5 votes
0 answers
215 views

Eagerloading Matrix fields resulting in empty array

I'm trying to eager-load a Matrix field with it's blocktype and related field types. For some reason the _eagerLoadedBlockTypeElements are empty arrays. If I get rid of the with clause on ...
Chris's user avatar
  • 51
4 votes
2 answers
6k views

How to output an Entries Field value within a Matrix Field block

I'm trying to code up a Matrix field for a homepage slider, and it contains a single 'Slide' block type. It has fields for Image (Assets), Heading (Plain Text), Sub-Heading (Plain Text), and Slide ...
Stephen's user avatar
  • 685
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
4 votes
1 answer
877 views

Is it possible to find what Matrix Block aren't being used

I have a fairly large site with the main content on most pages driven by a Matrix field. That Matrix field has 15 or so different Blocks - we are now doing a tidy up on the site and going to try and ...
mmc501's user avatar
  • 1,789
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
2 answers
319 views

How to output the matrix block type name in Craft? Possible feature request

Is it possible to output the block type name in Craft for each matrix block in your field? Currently Craft just lists the name of each field within the block, but we are using generic field names (...
Jamie Wade's user avatar
  • 3,644

1
2 3 4 5
14