Copied to clipboard

Flag this post as spam?

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


  • Rasmus Hummelmose 22 posts 72 karma points
    Mar 27, 2012 @ 13:55
    Rasmus Hummelmose
    0

    DynamicModel.AncestorsOrSelf.Where("metaBeskrivelse != @0", "null")

    Why does the following not work

    @if (DynamicModel.AncestorsOrSelf.Where("metaBeskrivelse != @0", "null").Any()) {
      <meta name="Description" content="@DynamicModel.AncestorsOrSelf.Where("metaBeskrivelse != @0", "null").First().metaBeskrivelse" />
    }

    I've also tried these other syntaxes

    DynamicModel.AncestorsOrSelf.Where("metaBeskrivelse != @0", null)
    DynamicModel.AncestorsOrSelf.Where("metaBeskrivelse != null")
    DynamicModel.AncestorsOrSelf.Where("metaBeskrivelse != @0", "")

    niether of which work. Please someone help me out here.

  • Rasmus Hummelmose 22 posts 72 karma points
    Mar 27, 2012 @ 13:56
    Rasmus Hummelmose
    0

    metaBeskrivelse is a string I have on an inheritence-only content-type called settings. All actual pages in my Umbraco installation inherit from this type.

  • Grant Thomas 291 posts 324 karma points
    Mar 27, 2012 @ 14:07
    Grant Thomas
    0

    Have you tried with title-casing? 'MetaBeskrivelse'

    I'm not sure it will ever equate to 'null' if the property actually exists (I could be wrong, though) but rather an empty string, as in your last example.

  • Rasmus Hummelmose 22 posts 72 karma points
    Mar 27, 2012 @ 14:12
    Rasmus Hummelmose
    0

    Now I have and without luck. In addition I can tell you that another property from the same inheritence-only type can be queried without problems with the following code.

    @{
        var root = @DynamicModel.AncestorsOrSelf.Last();
        var topNavigation = @root.DescendantsOrSelf.Where("topNavigation = @0", "True");
    }
    @{
        if (topNavigation.Any()) {
            <ul id="navigation">
                @foreach (var page in topNavigation) {
                    <li><a href="@page.NiceUrl" class="ajax">@page.Name</a></li>
                }
            </ul>
        }
    }
  • Dan Okkels Brendstrup 101 posts 197 karma points
    Mar 28, 2012 @ 11:58
    Dan Okkels Brendstrup
    0

    So as we discussed elswhere, DynamicModel._metaBeskrivelse should do the trick, right? Cf. the DynamicModel._propertyAlias syntax for recursive property fetching. Does that return a boolean value for the if-test by itself?

  • Rasmus Hummelmose 22 posts 72 karma points
    Mar 28, 2012 @ 12:11
    Rasmus Hummelmose
    0

    Yes so we have a temporary solution. Though this solves the problem to some extent, we still don't have the flexibility with Where() that Xpath used to provide. It would be really nice if someone who's actually involved in working on Umbraco 5, could provide us with an explanation of why the initial approach fails and how we're able to achieve the desired flexibility.

    The working code is as follows.

    @inherits RenderViewPage;
    @using Umbraco.Cms.Web;
    @using System.Linq;

    @{
      var root = DynamicModel.AncestorsOrSelf.Last();
      var ogimage = string.Format("http://{0}{1}", Request.Url.Host, Umbraco.GetMediaUrl(root.ogbillede));
      var metaBeskrivelse = DynamicModel._metaBeskrivelse;
      var metaNoegleord = DynamicModel._metaNoegleord;
    }
    @if (metaBeskrivelse != null) { <meta name="Description" content="@metaBeskrivelse" />
    }
    @if (metaNoegleord != null) {
      <meta name="Keywords" content="@metaNoegleord" />
    }
    <meta property="og:title" content="@Html.Partial("title")" />
    @if (root.ogbeskrivelse != null) {
      <meta property="og:description" content="@root.ogbeskrivelse" />
    }
    @if (root.ogbillede != null) {
      <meta property="og:image" content="@ogimage" />
    }
    <meta property="og:locale" content="da_DK" /> 
  • Alex Norcliffe 222 posts 287 karma points
    Mar 30, 2012 @ 15:35
    Alex Norcliffe
    0

    Hi there Rasmus, have you tried 5.0.1 (released) or the beta of 5.1? The following syntaxes have passing tests in those builds

    DynamicModel.AncestorsOrSelf.Where("metaBeskrivelse != @0",null)
    DynamicModel.AncestorsOrSelf.Where("metaBeskrivelse != null")
    DynamicModel.AncestorsOrSelf.Where("metaBeskrivelse != @0","")

    However, the code you have now is perfectly correct too, so if it's working for you, there's no rush to change

  • Alex Norcliffe 222 posts 287 karma points
    Mar 30, 2012 @ 15:40
    Alex Norcliffe
    0

    Forgot to mention - the 5.0.1 and 5.1 beta builds are available from http://umbraco.codeplex.com

     

Please Sign in or register to post replies

Write your reply to:

Draft