Copied to clipboard

Flag this post as spam?

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


  • Scott Leslie 28 posts 143 karma points
    Mar 17, 2014 @ 18:21
    Scott Leslie
    0

    Umbraco WebAPI Content

    I want to get access to the site content via the API

     

    Home

    -Section 1
    -Page1-1
    -Page1-2

    -Section 2
    -Page2-1
    -Page2-2

     

    I want to get an xml which i can then consume elsewhere (a seperate webforms application)

    Thanks

    Scott

  • Amir Khan 1287 posts 2744 karma points
    Mar 17, 2014 @ 18:54
    Amir Khan
    100

    You could use Razor to traverse through your content structure and output it however you'd like...The sample sitemap file would probably be a good place to start, then change the HTML to whatever XML markup you'd like:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
    @* Walk up the tree from the current page to get the root node *@
    var rootNode = Model.AncestorOrself(1);
    }

    @*Render the sitemap by passing the root node to the traverse helper*@
    <div class="sitemap">
    @traverse(@Model.AncestorOrSelf())
    </div>



    @*Helper method to travers through all descendants*@
    @helper traverse(dynamic node){

    @*If a MaxLevelForSitemap parameter is passed to the macro, otherwise default to 4 levels*@
    var maxLevelForSitemap = String.IsNullOrEmpty(Parameter.MaxLevelForSitemap) ? 4 : int.Parse(Parameter.MaxLevelForSitemap);

    @*Select visible children *@
    var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);


    @*If any items are returned, render a list *@
    if (items.Any()) {
    <ul>
    @foreach (var item in items) {
    <li class="[email protected]">
    <a href="@item.Url">@item.Name</a>

    @*Run the traverse helper again *@
    @traverse(item)
    </li>
    }
    </ul>
    }
    }
  • Scott Leslie 28 posts 143 karma points
    Mar 17, 2014 @ 18:58
    Scott Leslie
    0

    was think web-api. but yes a simple Macro rendering XML would do the trick. thanks

Please Sign in or register to post replies

Write your reply to:

Draft