Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matt 359 posts 842 karma points
    Apr 01, 2019 @ 12:32
    Matt
    0

    Creating a template and reusing it.

    Hello all,

    So I've created a template which I want them to be able to reuse to add different content. The template is a simple Collapsibles/Accordion.

    Everything works well for just 1 node, if I then create a new node (Matt test 2) using the accordion template it doesnt pick up the "working 2" and "working 3" it references the data from Matt test and not Matt test 2

    Here is my tree view;

    enter image description here

    Here is my code;

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Accordion>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "Master.cshtml";
    }
    
      <div class="body-section">
        <div class="body-container w-container">
          <h1 class="main-page-heading">@Umbraco.Field("pageTitle")</h1>
          <p>@Umbraco.Field("pageTopContent")</p>
    
       @{
        var selection = Model.Content.Site().FirstChild("accordion").Children("createCollapsible").Where(x => x.IsVisible());
    }
        @foreach(var item in selection){
          <div class="faq-wrapper">
            <a href="#" class="faq-link w-inline-block w-clearfix" data-ix="show-faq-answer">
              <div class="circle"></div>
              <div>@item.GetPropertyValue("collapsibleTitle")</div>
            </a>
            <div class="faq-answer" data-ix="hide-faq-answer">
              <p class="faq-answer-text">@item.GetPropertyValue("extendCollapsible")</p>
            </div>
          </div>
        }
    
          </div>
      </div>
    

    Anyone able to point me in the right direction?

    Thanks

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 9x admin c-trib
    Apr 01, 2019 @ 12:38
    Alex Skrypnyk
    0

    Hi Matt

    Can you show what is going on on the Info tab? What is the default template for this document type?

    Thanks,

    Alex

  • Darren Welch 23 posts 136 karma points c-trib
    Apr 01, 2019 @ 12:42
    Darren Welch
    100

    Your content is always grabbing the firstChild which will always be 'mattTest'.

    Try changing that to:

    @{
    var selection = Model.Content.Children("createCollapsible").Where(x => x.IsVisible()); }
    
  • Matt 359 posts 842 karma points
    Apr 01, 2019 @ 14:49
    Matt
    0

    Worked perfect, thanks Darren!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies