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.
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
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.
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.
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.
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 :
So if you´re using PartialViewMacroPage (MVC) you can access generic properties like this;
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.:
Then you can can access generic properties like this
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
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.
//fuji
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! ^^
You basically want to display bodyText from your About Page on every single page you have right?
Hope this helps
//fuji
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
is working on a reply...