Copied to clipboard

Flag this post as spam?

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


  • BEWD 89 posts 301 karma points
    May 11, 2016 @ 17:35
    BEWD
    0

    Adding @item.GetPropertyValue into a class

    Hi All,

    I am at the final stages of a project but am stuck on that final step.

    I have a partial view that forms part of a gallery, I want these gallery images to be filtered by a category (see below), I have this working in HTML

    enter image description here

    The category is specified via a drop down box when the item is added, however whilst the image appears when you select 'All' it does not appear when you select 'Slate' even though that is how it is tagged?

    The Partial view code is

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
    var selection = CurrentPage.Site().FirstChild("portfolioArea").Children("portfolioItem").Where("Visible");
    }
    <ul id="portfolio-grid" class="thumbnails row">
    @foreach(var item in selection){
                    <li class="span4 mix @item.GetPropertyValue.Category">
                        <div class="thumbnail">
                            <img src="@Umbraco.Media(item.Image).Url" alt="project 1">
                            <a href="#single-project" class="more show_hide" rel="#slidingDiv">
                                <i class="icon-plus"></i>
                            </a>
                            <h3>@item.Name</h3>
    
                            <div class="mask"></div>
                        </div>
                    </li>
    }
    </ul>
    

    When it renders on the page the HTML states

    <li class="span4 mix mix_all"> 
    

    even though Slate is selected.

    The options in the dropdown are exactly the same as the categories in the first picture.

    Any Ideas what I am doing wrong here?

    Thanks

    Ben

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 11, 2016 @ 19:34
    Jan Skovgaard
    0

    Hi Ben

    When you say you have it working in HTML what do you then mean by that? Is it a static HTML prototype? If so are you then making use of anchor/id and the :translate pseudo class in CSS? Or are you using a JavaScript like Isotope for instance? Or perhaps slick slider would be more appropiate in this case?

    However I'm a bit puzzled about what the issue is? :) Is it that when you click the categories "Brass", "Plastics" etc. that the images you expect to see do not appear?

    If you're not using some kind of JavaScript to achieve this then you would at least need to have a QueryString added, which Razor can look at and set the correct category based on what has been clicked.

    Looking forward to hearing from you and sorry if I'm missing something from your explanation above but I think that a bit more detail about how it's working in your static HTML will help understanding how to guide you on how to make it work when implemented in the CMS :)

    /Jan

  • BEWD 89 posts 301 karma points
    May 11, 2016 @ 20:58
    BEWD
    0

    Sorry Jan I have reviewed my post and can offer more helpfull information and even corrections :)

    Yes I do use some JavaScript to do this and it all works fine if I hard code the code to say 'Slate'

    So for example, If i click on the 'Slate' button when it is hard coded the HTML for that Li would look like below and I would see the images that have been tagged with the word slate via the Category property.

    <li class="span4 mix slate mix_all"">
    

    However if I use the <li class="span4 mix @item.GetPropertyValue.Category"> Then I get nothing when I click on the word slate and the html looks like

    <li class="span4 mix  mix_all">
    

    Note the double spaces between the two mix's in the code directly above, It is not outputting the value of Category.

    This may not be an Umbraco problem but that was my first thought.

    Cheers

    Ben

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    May 11, 2016 @ 21:21
    Dennis Aaen
    0

    Hi Ben,

    What if you do it like this would you then get the right value of the class

    @item.GetPropertyValue(‘Category’)

    Where Category are in single qoutes

    Hope this helps,

    /Dennis

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 12, 2016 @ 05:08
    Jan Skovgaard
    0

    Hi Ben

    No need to be sorry :-) And thanks for the extra information.

    Can you show what your static source looks like? I just need to see the whole context to fully understand how your code is supposed to be working since by looking at what is posted it seems to be "dark magic" - It might be that it's simply the "tag" value missing since it's not being rendered but looking at the code I'm wondering what the links/buttons for switching between the categories look like? Where do you get those values from? Are those also setup using the tags or are they hardcoded currently? If you have them rendered somewhere else using a foreach then I would like to see that code too since you should be able to re-use it I think.

    If it works by the latest suggestion made by Paul then that's just fine of course but I would love to see and understand the full context - So if you could post the static working code example that would be nice :) - If you have a temporary link for the dev-site then that would be ace.

    Looking forward to hearing from you.

    /Jan

  • BEWD 89 posts 301 karma points
    May 11, 2016 @ 21:38
    BEWD
    0

    Hi Dennis

    <li class="span4 mix @item.GetPropertyValue('category')"> doesnt work and neither does

    <li class="span4 mix @item.GetPropertyValue(category)">

    I have tried capitalising the C as well but no luck i'm afraid.

    I m missing something obvious im sure but you know what its like, I have been staring at it for ages and just cant crack it.

  • Paul Wright (suedeapple) 277 posts 704 karma points
    May 11, 2016 @ 22:17
    Paul Wright (suedeapple)
    101

    @item.Content.GetPropertyValue("category")

    Or

    @item.category

    Try that :)

  • BEWD 89 posts 301 karma points
    May 12, 2016 @ 06:39
    BEWD
    1

    @item.category worked a treat, I'm sure I had tried that as it is the most obvious.

    Looks like I was over complicating it. Cheers Paul

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 12, 2016 @ 07:20
    Jan Skovgaard
    0

    Hi Ben

    Happy to hear that it works for you :)

    Would still love to see your structure for the other pars mentioned - I'm just being curious that's all :)

    Cheers, Jan

Please Sign in or register to post replies

Write your reply to:

Draft