Copied to clipboard

Flag this post as spam?

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


  • Steve Brown 125 posts 290 karma points
    Jun 04, 2013 @ 23:01
    Steve Brown
    0

    getting node properties in umbraco 6

    I'm attemptint to retrieve node properties in a razor template in umbraco 6 and having some trouble. I'd like to get properties similar to how they fetch the title in this example http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/uquery-dynamic-title

    It appears there is no uComponents namespace in umbraco 6, or I don't know how to access it, so I'm not sure how to go about this exactly. Thanks for any guidance

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 04, 2013 @ 23:55
    Jeavon Leopold
    0

    Hi Steve,

    First question is, are you using .cshtml Mvc templates or .master MasterPage templates?

    Thanks,

    Jeavon

  • Steve Brown 125 posts 290 karma points
    Jun 05, 2013 @ 14:28
    Steve Brown
    0

    cshtml mvc

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Jun 05, 2013 @ 14:30
    Dave Woestenborghs
    2

    Also...do you have uComponents installed ?

    http://ucomponents.org/

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 05, 2013 @ 14:32
    Jeavon Leopold
    102

    Ok, so then you should do something like this for a textbox property with an alias of "pageTitleH1"

    @{ 
      if (Model.Content.HasValue("pageTitleH1")){
        @Model.Content.GetPropertyValue("pageTitleH1")
      } 
    }

    Lots of useful documentation available below:

    For different property editors: http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/

    For general MVC querying: http://our.umbraco.org/documentation/Reference/Mvc/querying

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 05, 2013 @ 14:38
    Jeavon Leopold
    4

    If you did specifically want to use uQuery then it now resides in the umbraco namespace rather than uComponents, there is full documentation for uQuery available here

     

  • Steve Brown 125 posts 290 karma points
    Jun 05, 2013 @ 14:45
    Steve Brown
    1

    well, i feel sheepish. I did not have ucomponents installed. once I added that my code worked as intended. Thank you for the tips, everybody. I will probably take a look at the documentation for uQuery and try to use it without uComponents if I don't need it for this.

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 05, 2013 @ 14:52
    Jeavon Leopold
    0

    If you do use uQuery, make sure you use it from the umbraco namespace rather than uComponents as that version is maintained only for legacy and isn't fully Umbraco v6 compatible.

  • Steve Brown 125 posts 290 karma points
    Jun 05, 2013 @ 15:55
    Steve Brown
    0

    I marked your snippet as the answer because it's pretty much what i used. Here's what I ended up doing for a redirect to an external URL

    @{
        var url = "";
        if (Model.Content.HasValue("customRedirectUrl")){
            url = Convert.ToString(Model.Content.GetPropertyValue("customRedirectUrl"));}
        if (!(string.IsNullOrEmpty(url))){
            Response.Redirect(url);}
     }
    
  • Steve Brown 125 posts 290 karma points
    Jun 05, 2013 @ 16:15
    Steve Brown
    0

    I also uninstalled uComponents. it broke my back office - I couldn't edit document type properties. One other question though, is there any built in document property I could set on a document node to do an internal redirect with a querystring? I saw the UmbracoInternalRedirectId property which is pretty close to what I want, I just want to set a querystring as well. My snippet above accomplishes that, just wondering if there was a better way.

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 05, 2013 @ 18:08
    Jeavon Leopold
    1

    Nope, the only way I can think of to include the querystring in the redirect is pretty much exactly what you have done.

    I think I would do url = Model.Content.GetPropertyValue<string>("customRedirectUrl") instead of using the Convert.ToString but doesn't matter :-)

  • Steve Brown 125 posts 290 karma points
    Aug 08, 2013 @ 16:58
    Steve Brown
    0

    I have another site now with masterpages. How would I accomplish this in a MasterPage? Using the same code doesn't throw an error, but Model.Content.GetPropertyValue

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 08, 2013 @ 17:09
    Jeavon Leopold
    0

    Hi Steve,

    When you say masterpages, are you using a Razor macro or a Razor embedded in the .master page or something else?

    Thanks,

    Jeavon

  • Steve Brown 125 posts 290 karma points
    Aug 08, 2013 @ 17:10
    Steve Brown
    0

    I tried both ways actually

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 08, 2013 @ 17:11
    Jeavon Leopold
    0

    Ok, can you post your whole .cshtml file Razor macro code?

  • Steve Brown 125 posts 290 karma points
    Aug 08, 2013 @ 17:12
    Steve Brown
    0

    Jeavon, to clarify, I tried using a cshtml razor macro and embedding razor in the .master page. Thanks for the reply.

  • Steve Brown 125 posts 290 karma points
    Aug 08, 2013 @ 17:17
    Steve Brown
    1

    a-ha! I just got it. I was missing the @inherits umbraco.web.macros.partialviewmacropage line. Here is the working cshtml razor macro in case it would help anybody else

    @using Umbraco
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        //custom redirect url property to allow redirect to external URLs or URL with query string
        Response.Write(Model.Content.GetPropertyValue<string>("customRedirectUrl"));
        var url = "";
        if (Model.Content.HasValue("customRedirectUrl")){
            url = Model.Content.GetPropertyValue<string>("customRedirectUrl");}
        if (!(string.IsNullOrEmpty(url))){
            Response.Redirect(url);}
    }
    
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 08, 2013 @ 17:19
    Jeavon Leopold
    0

    Great, I see you are actually using a Partial View Macro rather than a Razor Macro, slightly confusing names I guess.....

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies