Answers.Body: <p>The error has to do with the line <code>{% for block in entry.sectionaccordion %}</code> because it's looking for a field in your entry called <code>sectionaccordion</code> but <code>sectionaccordion</code> is not a field; it's a block <em>inside</em> a field (your matrix field).  So the error is basically saying "there is no field called 'sectionaccordion' for this entry".</p>
  
  <p>You also don't want to use a <code>for</code> loop here because there's nothing to loop through.  You're already looping through matrix blocks created in this matrix field, and your code is saying "if the block is of type <code>sectionaccordion</code>, print the contents of it."  The contents of that block won't be another loop; it'll only be 1 Accordion Title and 1 Accordion Text field.</p>
  
  <p>Lastly, by saying <code>{% elseif block.type == "sectionaccordion" %}</code>, you are eliminating the chance to display a slideshow since that is a different block type, one not called <code>sectionaccordion</code>.  If you want a slideshow inside your accordion block type, then you need to create a 3rd field for it inside <code>sectionaccordion</code> and just recreate whatever you did in the <code>sectionslideshow</code> block type.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-13T21:02:21.077Z
Answers.Text: Thanks, I think i realized what I was trying to do wont work with your second paragraph, since it would just be 1 accordian title and field.
  
  So how would someone compile a UL list using a matrix field? Thats basically what im trying to do.
Answers.UserDisplayName: kingkelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-14T04:01:36.343Z
Answers.Text: You'd probably need to just create a matrix field for this called `accordion` or whatever.  In that Matrix field, you'd only have one block type, and in that type you'd have the title and text fields.
Answers.UserDisplayName: Ryan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-15T04:54:20.363Z
Answers.Text: But thats not an option if you have a matrix field for filling up content on a page, and allowing the client to insert photos, text, buttons, captions etc. I want the accordian, or even a simple list, to be one of those options in the matrix field, so they can put it an any spot in their page.
Answers.UserDisplayName: kingkelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-13T20:50:46.143Z
Answers.LastActivityDate: 2017-10-13T20:50:46.143Z
Answers.UserDisplayName: Ryan
Answers.Body: <p>Add a new option in your page matrix (the one with lots of options for photos, text etc) - an entries field that links to a new section called 'faqs'.</p>
  <p>That 'faqs' section has one matrix in it - 'faqs', with two fields: 'faqTitle' and 'faqAnswer'.</p>
  <p>The code would be something like:
  <em>(you'd need to wrap it in your faq code, and assuming the entries field is in a matrix)</em></p>
  <pre><code>{% set relatedEntries = craft.entries.section('faqs').relatedTo(block) %}
  {% for rel in relatedEntries %}
  {% set relBlocks = rel.faqs.all() %}
  {% for relBlock in relBlocks %}
  {{ relBlock.faqTitle }}
  {{ relBlock.faqAnswer }}
  {% endfor %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-21T15:57:58.790Z
Answers.LastActivityDate: 2023-07-21T15:57:58.790Z
Answers.UserDisplayName: Jonathan
Body: <p>I'm trying to build an accordion in my matrix field (that also holds entries for a slideshow, button, image, etc).</p>
  
  <p>Im having trouble with getting each entry to go inside <strong>&lt; div id="accordion">&lt; /div></strong> and not repeat this accordion div over and over.</p>
  
  <pre><code>{% elseif block.type == "sectionaccordion" %}
  
      &lt;div id="accordion"&gt;
        {% for block in entry.sectionaccordion %}
          &lt;div class="accordiontitle"&gt;{{ block.accordionTitle }}&lt;/div&gt;
          &lt;div class="accordion-content default"&gt;
            {{ block.accordionText }}
          &lt;/div&gt;
        {% endfor %}
      &lt;/div&gt;
  </code></pre>
  
  <p>With this setup, I keep getting <em>Craft\EntryModel and its behaviors do not have a method or closure named "sectionaccordion".</em></p>
  
  <p><a href="https://i.sstatic.net/Vd725.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Vd725.png" alt="enter image description here"></a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-13T19:28:47.763Z
Comments.Text: Is ``entry.sectionaccordion`` another matrix field or a block inside another matrix? You can't do matrix within a matrix inside Craft...
Comments.UserDisplayName: RitterKnight
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-13T19:49:59.183Z
Comments.Text: Nope its just a block type in my matrix. Updated with an image of my matrix settings.
Comments.UserDisplayName: kingkelly
Tags: <matrix>
Title: Building an accordion with a Matrix field
ThreadText: # Building an accordion with a Matrix field
  
  (Asked by: username_0 on 2017-10-13)
  
  I'm trying to build an accordion in my matrix field (that also holds entries for a slideshow, button, image, etc).
  
  Im having trouble with getting each entry to go inside **< div id="accordion">< /div>** and not repeat this accordion div over and over.
  
  ```
  {% elseif block.type == "sectionaccordion" %}
  
      <div id="accordion">
        {% for block in entry.sectionaccordion %}
          <div class="accordiontitle">{{ block.accordionTitle }}</div>
          <div class="accordion-content default">
            {{ block.accordionText }}
          </div>
        {% endfor %}
      </div>
  
  ```
  
  With this setup, I keep getting *Craft\EntryModel and its behaviors do not have a method or closure named "sectionaccordion".*
  
  [![enter image description here](https://i.sstatic.net/Vd725.png)](https://i.sstatic.net/Vd725.png)
  
  **Tags:** matrix
  
  > **Comments:**
  > **username_1**: Is ``entry.sectionaccordion`` another matrix field or a block inside another matrix? You can't do matrix within a matrix inside Craft...  
  > **username_0**: Nope its just a block type in my matrix. Updated with an image of my matrix settings.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-10-13. Score: 3
  
  The error has to do with the line `{% for block in entry.sectionaccordion %}` because it's looking for a field in your entry called `sectionaccordion` but `sectionaccordion` is not a field; it's a block *inside* a field (your matrix field). So the error is basically saying "there is no field called 'sectionaccordion' for this entry".
  
  You also don't want to use a `for` loop here because there's nothing to loop through. You're already looping through matrix blocks created in this matrix field, and your code is saying "if the block is of type `sectionaccordion`, print the contents of it." The contents of that block won't be another loop; it'll only be 1 Accordion Title and 1 Accordion Text field.
  
  Lastly, by saying `{% elseif block.type == "sectionaccordion" %}`, you are eliminating the chance to display a slideshow since that is a different block type, one not called `sectionaccordion`. If you want a slideshow inside your accordion block type, then you need to create a 3rd field for it inside `sectionaccordion` and just recreate whatever you did in the `sectionslideshow` block type.
  
  > **Comments:**
  > **username_0**: Thanks, I think i realized what I was trying to do wont work with your second paragraph, since it would just be 1 accordian title and field.  So how would someone compile a UL list using a matrix field? Thats basically what im trying to do.  
  > **username_2**: You'd probably need to just create a matrix field for this called `accordion` or whatever.  In that Matrix field, you'd only have one block type, and in that type you'd have the title and text fields.  
  > **username_0**: But thats not an option if you have a matrix field for filling up content on a page, and allowing the client to insert photos, text, buttons, captions etc. I want the accordian, or even a simple list, to be one of those options in the matrix field, so they can put it an any spot in their page.  
  
  ---
  
  ### Answer by username_3 on 2023-07-21. Score: 1
  
  Add a new option in your page matrix (the one with lots of options for photos, text etc) - an entries field that links to a new section called 'faqs'.
  
  That 'faqs' section has one matrix in it - 'faqs', with two fields: 'faqTitle' and 'faqAnswer'.
  
  The code would be something like:
  *(you'd need to wrap it in your faq code, and assuming the entries field is in a matrix)*
  
  ```
  {% set relatedEntries = craft.entries.section('faqs').relatedTo(block) %}
  {% for rel in relatedEntries %}
  {% set relBlocks = rel.faqs.all() %}
  {% for relBlock in relBlocks %}
  {{ relBlock.faqTitle }}
  {{ relBlock.faqAnswer }}
  {% endfor %}
  {% endfor %}
  
  ```
  
  
  ---
  
  