Copied to clipboard

Flag this post as spam?

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


  • Keith 74 posts 240 karma points
    Jun 02, 2021 @ 09:15
    Keith
    0

    TagQuery marked as Obsolete on UmbracoHelper, but how do you use the alternative?

    Hi Everyone,

    I am trying to query a group of tags from a razor view. I can see from various discussions that the suggested approach for this used to be:

    @Umbraco.TagQuery.GetAllTags("SomeGroupName")
    

    But "TagQuery" has been marked as obsolete in the V8 code and removed in the V9 code. It says:

    "Inject and use an instance of ITagQuery in the constructor for using it in classes or get it from Current.TagQuery in views."

    But how do I use "Current.TagQuery" in my razor view? Because "Current" is not a property on the UmbracoHelper. So I cant just do:

    @Current.TagQuery.GetAllTags("SomeGroupName")
    

    I have tried including:

    @using Umbraco.Web.Composing
    

    Because, this is where the "Current" class exists in the code. But I get an error:

    "The type or namespace name 'Web' does not exist in the namespace 'Umbraco'"

    Can anyone advise how this is supposed to work?

    Thanks

    Keith

  • Bjarke Berg 29 posts 265 karma points hq
    Jun 02, 2021 @ 09:19
    Bjarke Berg
    100

    Hi..

    In views you can use the @inject keyword..

    @using Umbraco.Cms.Core.PublishedCache;
    @inject ITagQuery TagQuery;
    ...
    @TagQuery.GetAllTags("SomeGroupName")
    
  • Keith 74 posts 240 karma points
    Jun 02, 2021 @ 09:41
    Keith
    0

    Wow! Thanks

  • Anders Jensen 5 posts 75 karma points
    Oct 29, 2021 @ 08:19
    Anders Jensen
    0

    Hi, have any one tried the GetContentByTag("Test", "Group1") ? Is there a known bug ?

    I get 0 Content back, but I get all if I use the GetAllTags().

    Im testing out Umbraco 9

    EDIT: Found the issue, the tag name has to be lowercase to work.....

  • Angel 49 posts 105 karma points
    Sep 14, 2022 @ 14:57
    Angel
    0

    Hi, I am using Umbraco v8

    I am trying to use ITagQuery in a partial view for building out a block view.

    I tried to add the following : @inherits UmbracoViewPage

    the first issue is: Cms does not exist in the namespace Umbraco the second issue is: The name 'inject' does not exist in the current context

    What am I missing or doing wrong?

Please Sign in or register to post replies

Write your reply to:

Draft