Hot answers tagged

2

In this specific case, yes. You can filter your entry query by whether a specific matrix field has at least one block like so: {% set query = craft.entries({ section: 'blog', myMatrixField: ':notempty:', limit: 10 }) %} or for fields that have 0 matrix blocks in the specific field: {% set query = craft.entries({ section: 'blog', ...


2

I'm not entirely clear what your Matrix blocks/fields are setup like, so it's a little hard to tell what's going on here. But I'm going to take a stab at it. Your outer loop is looping through all the blocks in the calendarGroup Matrix field. Then you're using a switch to determine which piece of code to execute based on which one of the two block types ...


2

As John mentioned, restoring a database backup is your best bet. If you don’t have a recent backup, you may still be able to get your Matrix content back, thanks to semi-bug where Craft doesn’t actually delete Matrix block content, when a Matrix field is converted to something else. Here’s what you can try: Enable the Project Config file for your site, if ...


2

You have to loop the Matrix field first, something like this: foreach($entry->matrixHandle->all() as $block) { echo $block->fieldHandle; }


2

This solves my problem: {% for block in entry.transformerProductNavigation %} {% set chosenCategory = block.transformer.last() %} {# set a variable – chosenCategory to the 'last' category ensuring any nested categories are accessible #} <a href="{{ chosenCategory.slug }}">{{ chosenCategory.title }}</a> {% endfor %} Thanks to ...


2

during this process : {% set image = block.image.one() %} please make sure the name of handle of image is image. For example in this matrix the type is 'image' but to get image url you should call it. item.imageAssets.one().url


2

There is no way to determine if an image should go to the first block.type == 'A' if statement or the second one you could write something like this: {% switch block.type %} {% case 'A' %} {# images for both case a1 + a2. write the loop number into the class name #} <li class="cellA{{ loop.index }}"> {# your image #}</li> ...


2

According to the craft cms docs To show a “New Block” form, first come up with a temporary ID for the block, prefixed with new:. For example, new:1, new:2, etc. so, you need to you use prefix new: with the colon is a must.


2

Thanks Marten, yes, that's correct. After plugging away I have gotten it to work, but it's likely not as efficient as it could be... {% set today = now|date('Y-m-d') %} {% set todayday = now|date('l') %} {% for block in entry.closedDates.date('>=' ~ today).limit(1) %} {% set closedDate = block.date.format('Y-m-d') %} {% if closedDate == today %} ...


2

There may be a better answer, but this is what I have come up with. Using Control Panel JS, combined with Preparse field(s), I am adding characters in like this {% for thing in entry.myMatrixField %} {{ thing.item }} - {{ thing.amount|number_format(2, '.', ',') }}^ {% endfor %} And then using some basic jQuery to replace the ^ character with a line break. ...


1

Regarding performance: If you look at the database structure of Craft, you'll see that Matrix content is stored across multiple tables, with each block having its own record, just like entries do. I've never compared calculations, but I'd bet there's no significant difference in the DB performance between your two ideas. Using eager loading you could ...


1

This turned out to be a Craft bug. I’ve posted an issue for it at https://github.com/craftcms/cms/issues/5849, and fixed it for the next release (3.4.12).


1

But is the issue related to the size of the Matrix Field? Or overall the number of fields in the database? Neither. :) That error message isn't related to the linked Github issue (although I can see how you'd get them confused). It's coming from the Craft's Plain Text field type: https://github.com/craftcms/cms/blob/develop/src/fields/PlainText.php#L126-...


1

You only use new1, new2 etc for creating new matrix blocks during the submission. For editing existing blocks, you need to use the block's ID in that same place. In your case that would be block.id.


1

Try checking for |length {% if image|length %} {{ image.url }} {% endif %}


1

block.image is actually an array (even if only 1 image in it) therefore you need to loop over it so try this... {% for image in block.image.all() %}{{ image.url }}{% endfor %} If you want to check that there is an image first you can use this.. {% if block.image|length %} ... {% endif %}


1

In reply. In a tweet from Brandon... Neo will get a direct upgrade path to matrix. https://twitter.com/brandonkelly/status/1114144432243265536?s=19 That being said. I used supertable more recently.


1

'allowAdminChanges' => false on your production server is also a tip I can give you.


1

There really isn't a "proper/best practice" that fits all situations. Any determination will depend on the complexity of the data, and what you plan to do with it (both now and in the future). For example: If the data is simple (i.e. text or other simple field type), likely to be unique or one-offs, not linked to anything else, only 1 level deep, and only ...


1

Probably you would want to use: Users field as a relation to one or more of the users Categories field as a relation to one or more of the categories


1

After further research, i got to the same answer. I can either use the plugin called Neo or Supertables. It has also being mentioned that they will both get moved as native functionality in craft 4. https://github.com/craftcms/cms/issues/812#issuecomment-516975780 Both accomplish the same thing, although even if Neo is more popular I found Supertables ...


1

I see what you're asking. Instead of using SuperTable, you could create a block type that has two rich text fields in it, Column 1 and Column 2. Alternately, you can create a separate channel for repeating content types (a CTA, for example) and make a block type that simply relates to that content (block type is 'entries').


1

Restore your database from a recent backup is your only real option tbh.


1

Thank you, Jeremy, for helping out! I really appreciate it. I solved the issue today using the "Super Table"-plugin (matrix within a matrix). {% extends "layout.html" %} {% block calendar %} {% for row in entry.eventCalendar.all() %} <div class="row no-gutters"> {% for block in row.months.all() %} <div class="col-12"> <div class="...


1

If by grouping you mean wrapping each groups in a <div> for example, this should do it for you: {% set groupCount = 0 %} {% for block in entry.blocks %} {% switch block.type %} {% case "headingBlock" %} {{ groupCount > 0 ? '</div>' }}<div> {{ block.header }} {% set groupCount = groupCount ...


1

You need to use 'currentUser' to access the field. So; {% for block in currentUser.myMatrix %} {{ block.myMatrixField1 }} {{ block.myMatrixField2 }} {% endfor %} As for creating a new record in the matrix (I'm guessing you mean from the front end) then you need to create a form that submits the current matrix data alongside your new block data. This ...


1

You could wrap this in another for loop and put a condition on the inner fors, something like {% for option in myPositionDropdown %} <h2>{{ option.value }}</h2> {% for position, playersInPosition in playersGrouped if position == option.value %} <ul> {% for player in playersInPosition %} {% set playerData = craft....


1

Matrixmate is an awesome plugin that allows you to do the tabbing for Matrixes. That's it's primary focus, and it's free. https://plugins.craftcms.com/matrixmate Another awesome thing, is that you configure it with a php file in the config folder. I find this convenient because I easily carry over the feature to other websites that are structured the same ...


1

You can just add each matrix row data inside a wrapper with an ID of matrix row: <form id="some-custom-form" method="post" accept-charset="UTF-8" enctype="multipart/form-data"> {{ csrfInput() }} {{ redirectInput('/where-you-need') }} {{ actionInput('users/save-user') }} {{ hiddenInput('userId', currentUser.id) }} {% for block in ...


1

I ran into this issue recently updating a Craft 3.0.37 site to 3.2.x The issue turned out to be SuperTable plugin which also needed to be updated to more recent version.


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