I set up a form structure with a matrix. Now I would like to call the entries one by one. My first idea was to loop through them, but the outcome is that the entries are displayed alltogether.

Then I tryed to call them simply by the slug. Since there are just 4 of them. Not very dynamic though.

How can I call the sets of matrix contents one by one?

{% set form = craft.entries({section: 'registration', slug: 'form_1',}) .first() %}

Didn't work. Still alltogether.

  • What are you going to do with them afterwards? I'm not really sure why you don't want to have them as array so you can do form[0], form[1] – Robin Schambach Apr 6 '18 at 10:49
  • The matrix entries are displayed as registration forms on the site. I do want to have the as array. But there are several arrays which I want to show seperately. Now they show all at once. – analog junkie Apr 6 '18 at 10:58
  • Then you might not want to loop through the array directly? – Robin Schambach Apr 6 '18 at 11:05

In order to get all elements from an ElementCriteriaModel you need to call the find() function

{% set form = craft.entries({section: 'registration'}).find() %}

You can them access those with normal array indexes

| improve this answer | |
  • Can I access them with slugs? Do I need to make the slugs look like this: form[1], form[2]? – analog junkie Apr 9 '18 at 15:17
  • Yes you can get your entries via slug as well {% set form1 = craft.entries({section: 'registration', slug: 'form_1',}) .first() %} {% set form2 = craft.entries({section: 'registration', slug: 'form_2',}) .first() %} and so on. You can grab them all with one query as well, when you do {% set forms = craft.entries({section: 'registration', slug: ['form_2', 'form_1']}).find() %} or if the slugs are equal – Robin Schambach Apr 9 '18 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.