Copied to clipboard

Flag this post as spam?

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


  • Dustin 15 posts 105 karma points
    Dec 09, 2015 @ 15:31
    Dustin
    0

    Query to list results by a certain tag

    What I am trying to figure out is to modify this query to list only the content with a certain tag, "teller". The doctype is "page" with some text and a tag selection. The following is working, it just lists everything. Can someone point me in the right direction?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    
    @{
        var selection = CurrentPage.Site().FirstChild("ApplicationDatabase").Children.Where("Visible");
    }
    
    <div class="container">
        <!-- Page Features -->
        <div class="row text-center">
        @foreach(var item in selection){
                @:<div class="col-md-3 col-sm-6 hero-feature">
                    @:<div class="thumbnail">
                        <img src="@Umbraco.Media(item.ApplicationImage).Url" alt="">
                        @:<div class="caption">
                            <h3>@item.ApplicationName</h3>
                            <p>@item.ApplicationDescription</p>
                            <p>
                                <a href="" class="btn btn-primary">Open</a> <a href="@item.url" class="btn btn-default">More Info</a>
                            </p>
                        @:</div>
                    @:</div>
                @:</div>
        }        
    </div>
    
  • gary 385 posts 916 karma points
    Dec 09, 2015 @ 18:34
    gary
    0

    Hi Dustin

    Without seeing your tree and properties can't be too specific, but can give some ideas.

    @{
    var selection = CurrentPage.Site().FirstChild("ApplicationDatabase").Children.Where("Visible && "yourtagpropertyname" == "teller");
    

    }

    or

    @foreach(var item in selection.Where("yourtagpropertyname" == "teller")
    

    or use an if statement in the foreach, so if item.yourtagname == teller.

    Can't help but notice your @: , you should not need them, and you should be able to remove the @ on the foreach. I think what is throwing your code is the , if you take that outside the container div it will make life a bit easier for you.

    Hope it helps

    Gary

  • Dustin 15 posts 105 karma points
    Dec 09, 2015 @ 19:27
    Dustin
    0

    I don't why but it complains about not being able to use the && because one is a bool and the other is a string.

    CS0019: Operator '&&' cannot be applied to operands of type 'string' and 'bool'
    

    Another strange thing I have notice is that my code only works when i put the @: in front of the divs. I dont understand what you meant about that in the last post about making my life easier.

    Here is a screenshot of my tree and properties. Thanks for helping I am still very new to this.

    enter image description here

    enter image description here

  • gary 385 posts 916 karma points
    Dec 09, 2015 @ 20:01
    gary
    0

    Hi Dustin

    Will give you some code and try to explain it as we move.

    @{ var topNode = CurrentPage.AncestorOrSelf() }
    

    OK, this var will take you from the page you are on, to the top of the content tree . As I cannot see that tree, if your top node is at position 0, this will work, if your top node is the one below that, put a 1 inside the brackets.

    @{foreach var item in topNode.Descendants("ApplicationName").Where("yourPropertName" == "teller"){ ..........}
    

    This foreach will go down the content tree until it finds a document type called ApplicationName. I cannot see on what document type your property that can have the value of "teller" is, so you will need to substitute as required. The Where statement should contain the name of the property on the doctype that equals "teller".

    In theory that should work.

    The @: this is to break the code? But does make your code really confusing with @ and @:

    If you use @{ before the foreach, as above, the code block should remain open, but I have just noticed that your row text-center div starts outside the block and finishes inside it, that is what is confusing the razor. Moving the outside the } will mean you can remove the @:s. My comment was not to offend but help by cleaning it up a bit, making it easier to see the blocks.

    Hope this helps, happy yo help further if you need.

    Regards

    Gary

  • Dustin 15 posts 105 karma points
    Dec 09, 2015 @ 21:40
    Dustin
    0

    I just realized something, in this code:

    @{foreach var item in topNode.Descendants("ApplicationName").Where("yourPropertName" == "teller"){ ..........} 
    

    teller is the tag I am trying to find by. I noticed you said "should contain the name of the property on the doctype that equals "teller"."

  • Dustin 15 posts 105 karma points
    Dec 09, 2015 @ 20:54
    Dustin
    0

    AHH!! thank you thank you. I didnt realize my div was inside the block. I fixed that and now I dont have to use the @: anymore.

    I am still having trouble with this query. I am going to attach the pictures you need. I have applied this and when it runs i dont get an error but nothing loads, just the rest of the page template.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{ var topNode = CurrentPage.AncestorOrSelf(); }
    
    
        <div class="container">
            <!-- Page Features -->
                <div class="row text-center">
        @foreach ( var item in topNode.Descendants("ApplicationDatabase").Where("applicationUsers" == "Teller")){
                <div class="col-md-3 col-sm-6 hero-feature">
                    <div class="thumbnail">
                        <img src="@Umbraco.Media(item.ApplicationImage).Url" alt="">
                        <div class="caption">
                            <h3>@item.ApplicationName</h3>
                            <p>@item.ApplicationDescription</p>
                            <p>
                                <a href="" class="btn btn-primary">Open</a> <a href="@item.url" class="btn btn-default">More Info</a>
                            </p>
                        </div>
                    </div>
                </div>
        }        
    </div>
    

    enter image description here

  • gary 385 posts 916 karma points
    Dec 09, 2015 @ 21:01
    gary
    0

    Hi Dustin

    We are getting somewhere.

    Rather than ask loads of stuff, if you remove the Where statement, see what returns,

    If nothing, put the 1 inside the AncestorsOrSelf(1), like that.

    If something returns, then applicationUsers, maybe ApplicationUsers.

    It's now something simple, so should get result soon.

    Cheers

    gary

  • Dustin 15 posts 105 karma points
    Dec 09, 2015 @ 21:03
    Dustin
    0

    Thanks for your help!!

Please Sign in or register to post replies

Write your reply to:

Draft