2

I'm using Piranha Core 8 with Aspnetcore 3. So far everything is going well. (I love Piranha!) My current problem is when building a Sidebar with a list of categories. I can't figure out how to retrieve all categories from the Api.

So far, I can get a list of posts, and perhaps iterate over them to collect the categories but this seems inefficient.

Any one know how to retrieve a list of all the categories from the cshtml pages?

Daniel Retief Fourie
  • 626
  • 2
  • 10
  • 20

2 Answers2

3

You can get the full list of taxonomies per Archive by calling the Api.

var categories = await api.GetAllCategoriesAsync(archiveId);
var tags = await api.GetAllTagsAsync(archiveId);

Best regards

Håkan Edling
  • 2,723
  • 1
  • 12
  • 15
  • Thanks so much. I saw that and got it working a few hours after posting. I'm an iOS dev by trade, so without documentation I am a little lost. Visual studio's assembly browser gave me a hint. Also, just so you know, I've looked at a bunch of dotnetcore CMS's and Piranha is by far my favourite! – Daniel Retief Fourie Jan 13 '20 at 08:49
0

From the razor page I got it working this way :

    @{
        var archiveId = WebApp.CurrentPost == null ? WebApp.CurrentPage.Id : WebApp.CurrentPost.BlogId;
        var categories = await WebApp.Api.Posts.GetAllCategoriesAsync(archiveId);
        var tags = await WebApp.Api.Posts.GetAllTagsAsync(archiveId);
    }
Barcollin
  • 87
  • 11