Copied to clipboard

Flag this post as spam?

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


  • David Zweben 268 posts 754 karma points
    Jun 13, 2016 @ 21:48
    David Zweben
    0

    Where to learn about Umbraco Razor methods/functions/options available?

    Hello,

    I'm trying to learn more about what Razor commands are available to use in Umbraco templates, especially ones made available when common @inherits and @using lines are included, like "umbraco.cms.businesslogic"?

    I would expect to be able to find some master list of what commands are available, but I haven't been able to find anything.

    What's the best way to learn about what Razor commands are available to use? Where or how can I find out what options/functions are available with these?

    Specifically, I was trying to use the line below from the example here: http://24days.in/umbraco/2014/razor-language-switcher/

    var currentLang = Domain.GetDomainsById(Model.Content.AncestorOrSelf(1).Id)[0].Language;
    

    I believe this is shorthand for this:

    umbraco.cms.businesslogic.web.Domain.GetDomainsById(Model.Content.AncestorOrSelf(1).Id)[0].Language;
    

    It didn't work, but I couldn't find any information on it. Any help would be appreciated.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jun 14, 2016 @ 05:06
    Jan Skovgaard
    0

    Hi David

    What kind of error message do you see when you try to use that line?

    I have been doing something similar at another project once, which was inspired by Søren's approach. Unfortunately I can't access the project anymore so can't digg in and see what I exactly did - I modified the code at bit to fit my specific scenario - But as mentioned I'm wondering what the error message you're seeing is? And have you setup some domain names for some of your websites in the Umbraco backoffice? For a list of available method, filtering etc. you can have a look at Peter Gregorys Razor cheatsheet here

    Don't worry that it says v6 - I don't think any of this has changed in any v7 releases yet.

    But also keep in mind that Razor is a subset of C# so you're able to use C# methods, which are not Umbraco specific as well.

    Looking forward to hearing from you.

    /Jan

  • David Zweben 268 posts 754 karma points
    Jun 14, 2016 @ 12:32
    David Zweben
    0

    Thank you, Jan!

    I remember those documents, good to know they're still relevant. They don't seem to mention anything relating to "umbraco.cms.businesslogic.web" methods, such as "Domain.GetDomainsById", though. Is there someplace I can find a similar document that includes info on that? Even in the Umbraco source code, perhaps?

    The reason I'm asking generally about how to learn more is that I don't have any domains set up (currently running Umbraco on localhost), so it's not surprising I'm getting errors, and I would be modifying the example anyway. I need to learn more about the methods used so I can adapt them, and to learn more about Razor in general. Right now I'm trying to find all the Umbraco-specific Razor documentation I can get.

    It would help a lot to have a list of methods and their options, and be able to test them by returning their value as plain text. I've tried to do this using the lines below:

    @{
    var currentLang = Domain.GetDomainsById(Model.Content.AncestorOrSelf(1).Id)[0].Language;
    }@
    
    @currentLang.ToString();
    

    But I just get this text output on the page:

    umbraco.cms.businesslogic.language.Language;
    

    How could I view the value of currentLang as plain text? Thanks.

    (To explain a bit more about our specific scenario, a 1-to-1 translation structure probably won't work for us, because we need to keep it a single site with a uniform structure, so I'm trying to test out a structure where translations are stored as no-template child nodes of each web page, which the web page pulls in dynamically. This is the example I'm referencing: http://24days.in/umbraco/2014/razor-language-switcher/)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 14, 2016 @ 13:00
    Dennis Aaen
    0

    Hi David,

    I besides the stuff Jan´s links too. Have a look at the the videos about Razor stuff and syntax of Razor.

    https://umbraco.tv/videos/umbraco-v7/implementor/working-with-umbraco-data/razor-syntax/

    https://umbraco.tv/videos/umbraco-v7/implementor/working-with-umbraco-data/querying-umbraco-data-with-razor/

    Hope this helps,

    /Dennis

  • David Zweben 268 posts 754 karma points
    Jun 14, 2016 @ 12:53
    David Zweben
    0

    I partially answered my own question by finding the GetDomainsById method in the Umbraco source code. This will help learn about these types of methods.

    https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/umbraco.cms/businesslogic/web/Domain.cs

    I'm still not sure why I I just get "umbraco.cms.businesslogic.language.Language;" or similar when I try to output the value as text, though.

    Any suggestions would be appreciated.

Please Sign in or register to post replies

Write your reply to:

Draft