Copied to clipboard

Flag this post as spam?

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


  • Jens Kvist 10 posts 30 karma points
    Feb 04, 2014 @ 20:20
    Jens Kvist
    0

    Get generic properties from a page

    Hello guys!

    I just started using Umbraco for 2 days ago, and I must say... It's a pretty awesome CMS. Anyway, now you know that I am a newbie at this. So I hope you guys could help me with something.

    I need to make a script that takes the generic properties from my About page. I have the "Title" and the "bodyText" property, that I would like to display when I drag n drop my macro into my site. Pretty simple, but as I explained earlier. I am new at this, so I don't know how to do it, or it explain it.

    Well, I hope you peeps understand my bad english and ability to explain this new language.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 04, 2014 @ 20:58
    Dennis Aaen
    1

    Hi Jens and welcome to Our!

    There are several ways on how to get generic properties on a page in Razor. It depends on whether you are using MVC or MacroScripts Razor.

    If you´re using a 7.x.x version the defaultRenderingEngine is set to use MVC. A way that you can see if you´re using MVC or MacroScripts is when you´re creating your macros.

    If you´re using want to use MVC it looks like this and you have to create it under the folder Partial View Macro Files in the developer section :

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    So if you´re using PartialViewMacroPage (MVC) you can access  generic properties like this;

    @CurrentPage.Title 
    @CurrentPage.BodyText

    If you´re using  MacroScripts when you creates a empty macroScript file it looks like this (Remember to use cshtml and not VBscript) It´s under the Scripting files folder in the developer section too.:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    Then you can can access  generic properties like this

    @Model.Title 
    @Model.BodyText

    I have linked to the basic Razor syntax http://our.umbraco.org/documentation/Reference/Templating/Macros/Razor/basic-razor-syntax if you´re using MVC look here: http://our.umbraco.org/documentation/reference/templating/Mvc/views

    I hope this can help you. If you have any other question related to this topic just keep asking, or if you have other Umbraco related question then just create a new topic on the forum.

    /Dennis

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 05, 2014 @ 03:51
    Fuji Kusaka
    0

    Hi Jens,

    As Dennis outlined there are different ways to render generic properties depending on the version of umbraco.

    If you are using older version such as v4 -v6 you can also make use of umbraco field which can be inserted directly in the template.

    <umbraco:Item field="title" stripParagraph="false" runat="server" />
    <umbraco:Item field="bodyText" stripParagraph="true" runat="server" />

    //fuji

  • Jens Kvist 10 posts 30 karma points
    Feb 05, 2014 @ 08:25
    Jens Kvist
    0

    Thanks for your answers! It helped alot, but unfortunately it did not answer my question.

    To be more specific with my question. The macro is going to be in my footer as a "quick view" for my About page. So whatever page you are on, there will be displayed my "bodyText" from the About page.

    Hope you understand! ^^

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 05, 2014 @ 09:28
    Fuji Kusaka
    0

    You basically want to display bodyText from your About Page on every single page you have right?

    var abtpage = Model.NodeById(1234);
    
    If(abtpage.HasValue("bodyText"){@abtpage.bodyText }
    

    Hope this helps

    //fuji

  • Jens Kvist 10 posts 30 karma points
    Feb 05, 2014 @ 10:31
    Jens Kvist
    0

    Thanks for your help guys! My final script looks like this:

    @inherits umbraco.MacroEngines.DynamicNodeContext

        @{
            var PageNodeID = Parameter.nodeId;
            var page = Library.NodeById(PageNodeID);
        }

    @page.bodyText

Please Sign in or register to post replies

Write your reply to:

Draft