Copied to clipboard

Flag this post as spam?

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


  • Kieron 152 posts 390 karma points
    Sep 10, 2018 @ 10:58
    Kieron
    0

    Hi guys, I'm trying to build a page that returns all content that has a matching tag, in this case, I'm just using a test tag, but ideally, I would modify this to pull the tags from a URL string etc.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.SearchResults>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = null;
    }
    
    <ul>
        @{
            var taggedContent = UmbracoContext.Application.Services.TagService.GetTaggedContentByTag("test").Select(x => x.EntityId);
            foreach (var contentItem in Umbraco.TypedContent(taggedContent).Where(x => x != null))
            {
                <li>@contentItem.Name</li>
            }
        }
    </ul>
    

    I have the above in a template, which works, but obviously no master template, its when I add a template of say Master, that I get this:

    Cannot bind source content type Umbraco.Web.PublishedContentModels.SearchResults to model content type Umbraco.Web.PublishedContentModels.Master. Both view and content models are PureLive, with same version. The application is in an unstable state and should be restarted.
    

    I think I'm merging 2 types of data, but not sure how to resolve!

    I can't find any documentation from recent years on using tags the best way, maybe this isn't the best way? so any help appreciated! thanks!

    Ideally id like some method to do the below:

    1. If one tag is given, look for matches
    2. if multiple tags are given, look for anything that contains any of the given tags

    Issue being that the above code only works for 1 tag i think?

  • Veerapandiyan Rajagopal 4 posts 96 karma points
    Sep 12, 2018 @ 17:52
    Veerapandiyan Rajagopal
    1

    Well, I moved your code into a partial view and placed the partial view on the search template page. It seems to be working fine for me. This might solve your issue#1. Will this work or am I missing something?

  • Kieron 152 posts 390 karma points
    Sep 12, 2018 @ 17:57
    Kieron
    0

    Hey, when I give the page a template, so Layout = master.cshtml for example, it gives me that error. Also point number 1 is no good unless point 2 also works, 1 tag is useful in some scenarios but for stuff like related articles, you want to compare all tags to all tags really.

    Hope that makes sense.

Please Sign in or register to post replies

Write your reply to:

Draft