1

Lets say I have a page structure like so

 - Books
      - Lord of the rings
      - Harry potter
      - Mice and Men

Now I want to display the titles of all those child pages on the book page. I found one question related to this: Piranha CMS: how to find child pages for a page

But when trying to use the api service I get

Unable to resolve service for type 'Piranha.Api'

I have services.AddPiranha(); In my configuration, and I dont see any other service that would be more apropriate to add.

I am running dot net core 2.2 and Piranha 7.0.3

Anyone got any suggestions?

user1593846
  • 734
  • 1
  • 15
  • 34

1 Answers1

2

The type that you should inject is Piranha.IApi, the class Piranha.Api is the default implementation of it!

Best regards

Håkan Edling
  • 2,723
  • 1
  • 12
  • 15
  • That worked perfectly thank you. Where in the documentation did you find this? And is there a way to get more content from the child page than just the title? lets say the child page has a image, title and description. – user1593846 Oct 21 '19 at 06:29
  • 1
    Hi! If you look at the project template all Pages/Controllers get the IApi interface injected. As you say this is probably not stated in the docs anywhere. If you want to get the full Page model for an item you should get api.Pages.GetByIdAsync(...) where you pass in the Id from the Sitemap Item you got from your previous code. Like you say, may parts of the docs could be clearer, but we're working on restructuring it right now for our new site, so hopefully it will improve. The docs will be moved to GitHub as well so you can always file an issue or send a PR with suggestions! Regards – Håkan Edling Oct 21 '19 at 09:20