Search code examples
dotnetnukedotnetnuke-module2sxc

2sxc | FAQ with Categories App | Add Link to each module app list item


I added '@Content.Link' to Razor template for the 'Simple list of questions' FAQ app. Problem is it gives each list item the same link. How do I set it so that each list item can have its own different link.

Thx

UPDATE: See current Razor code below

@using ToSic.SexyContent

<ol>
    @foreach (var q in AsDynamic(Data["Default"].List))
    {
    <div class="container" onclick="location.href='@Content.Link';">
        <li class="sc-element faq-set" data-tags="@String.Join(",", ((List<DynamicEntity>)q.Categories).Select(a => AsDynamic(a).EntityId))">
            @q.Toolbar

            <div class="faq-answer">@Html.Raw(q.Answer)</div>
            <h5><a href="@Content.Link" class="faq-question">
                @q.Question 
                <a href="@Content.Link">
                <span class="co-link">+ DOWNLOAD PDF</span>
                </a>
            </a></h5>
        </li>

    </div>
    }
</ol>

This works fine for a single link but if I add a new question and set a different link it is linked to first question link. New to Razor!

Appreciate any input......

Thx


Solution

  • Here's the corrected code - you should have used q (the loop variable) instead of Content

    @using ToSic.SexyContent
    
    <ol>
        @foreach (var q in AsDynamic(Data["Default"].List))
        {
        <div class="container" onclick="location.href='@q.Link';">
            <li class="sc-element faq-set" data-tags="@String.Join(",", ((List<DynamicEntity>)q.Categories).Select(a => AsDynamic(a).EntityId))">
                @q.Toolbar
    
                <div class="faq-answer">@Html.Raw(q.Answer)</div>
                <h5><a href="@q.Link" class="faq-question">
                    @q.Question 
                    <a href="@q.Link">
                    <span class="co-link">+ DOWNLOAD PDF</span>
                    </a>
                </a></h5>
            </li>
    
        </div>
        }
    </ol>