Questions tagged [matrix]

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

Filter by
Sorted by
Tagged with
29
votes
4answers
17k 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 ...
17
votes
5answers
5k 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 ...
16
votes
1answer
2k 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 ...
14
votes
2answers
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?
13
votes
5answers
6k 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" ...
11
votes
3answers
1k 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, ...
11
votes
1answer
2k 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 ...
11
votes
2answers
2k 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 ...
11
votes
2answers
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?
10
votes
2answers
2k 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 ...
9
votes
3answers
6k 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 ...
9
votes
2answers
876 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>{{ ...
8
votes
1answer
2k 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, ...
8
votes
2answers
2k 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)
8
votes
1answer
803 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 ...
8
votes
1answer
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 ...
8
votes
1answer
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. ...
7
votes
4answers
3k 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 (...
7
votes
4answers
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 ...
6
votes
4answers
3k 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,...
6
votes
3answers
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 ...
6
votes
1answer
504 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 ...
6
votes
1answer
363 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 ...
6
votes
1answer
550 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 %} {% ...
5
votes
4answers
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?...
5
votes
2answers
1k 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 ...
5
votes
2answers
418 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 ...
5
votes
3answers
1k 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 ...
5
votes
2answers
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 ...
5
votes
2answers
1k 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 ...
5
votes
1answer
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="...
5
votes
1answer
1k 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 ...
5
votes
2answers
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 '...
5
votes
1answer
663 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. ...
5
votes
1answer
57 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 ...
5
votes
1answer
929 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 ...
5
votes
1answer
641 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 ...
5
votes
1answer
260 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 ...
4
votes
2answers
5k 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 ...
4
votes
2answers
856 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-...
4
votes
3answers
2k 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 ...
4
votes
2answers
855 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 ...
4
votes
2answers
286 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 (...
4
votes
1answer
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....
4
votes
1answer
2k views

{% if loop.first %} and {{ loop.index0 }} not working with Matrix

I have a problem with {% if loop.first %} and {{ loop.index0 }} with the following snippet: {% for block in entry.locationSlideshow %} {% switch block.type %} {% case 'upload' %} {% for ...
4
votes
3answers
899 views

Return specific Matrix row?

I'm looking to be able to return the info from a field(s) from a Matrix row where I know which row I want (long story). I had a guess at various ways of doing this, but in the end the only way that ...
4
votes
1answer
220 views

Limiting the Upload Location for assets in a Matrix Block

In the Dashboard, while editing the settings of a Matrix Block — the instructions for setting Upload Location for an Assets field says Note that the subfolder path can contain variables like {owner....
4
votes
1answer
525 views

Reverse Related entries with Matrix Field

I have a site with channels ‘articles’ and ‘tutorials.’ An article entry has a matrix field which contains an entry field to link to a tutorial. Every tutorial is linked from within at least one ...
4
votes
3answers
2k 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 ...
4
votes
2answers
659 views

Is it possible to prevent disabled Matrix Blocks showing in a Live Preview?

I have a template which loops through Matrix Blocks. The site itself correctly ignores any Blocks which are 'disabled', but on viewing the page in the Live Preview, those Blocks are visible. A key ...

1
2 3 4 5
12