Copied to clipboard

Flag this post as spam?

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


  • J 447 posts 864 karma points
    Mar 17, 2016 @ 12:27
    J
    0

    Loop through pages

    I have a folder within Umbraco (6) that has some child pages. Each child page has an image and their name

    **Parent (Parent Folder)

    Child1 (Child page)

    Child2 (Child page)

    Child3 (Child page)

    Child4 (Child page)**

    I have some javascript on the template used by the parent page. What i would like to do is to loop through the child pages, so i can return each of their names and image.

    How could i loop through the pages and get the relevant info?

  • Søren Kottal 713 posts 4571 karma points MVP 6x c-trib
    Mar 17, 2016 @ 12:49
    Søren Kottal
    0
    @foreach (var childPage in Model.Content.Children)
    {
       var img = Umbraco.TypedMedia(childPage.GetPropertyValue("img"));
       if (img != null) {
          <img src="@img.Url">
       }
       <p>@childPage.Name</p>
    }
    
  • J 447 posts 864 karma points
    Mar 17, 2016 @ 13:36
    J
    0

    Would this work even though im not using MVC?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 17, 2016 @ 19:16
    Jan Skovgaard
    0

    Hi J

    How are you rendering data on your site currently? Are you using XSLT? Or user controls? Or umbraco:item tags? Just asking to figure out how to help you since a Razor response does not make sense if you're using XSLT and the other way around if you're using Razor then the XSLT example won't make any sense :)

    It's been a while since I had a look at v6 (and web forms in general) so can't quite remember whether Sørens example would work directly or if you should use macroscripts...

    /Jan

  • J 447 posts 864 karma points
    Mar 18, 2016 @ 09:17
    J
    0

    Hi, i ditched this idea as i figured out XSLT doesnt allow javascript so i am now trying with a chtml. Thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 18, 2016 @ 09:26
    Jan Skovgaard
    0

    Hi J

    You can write it in CDATA section but I'm not sure what it is you want to achieve and why you want to mix JavasSript and XSLT? Or JavaScript and Razor for that sake?

    Any particular reason why that JavaScript can't be run from it's own seperate file hooking into an id or a class?

    /Jan

  • 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