We have some legacy .net code, which we would like to use as macros. I have created the macro, and added a few parameters, and the macro can be inserted in RTE.
My question is, how do i retrieve the macro parameter value in my .net code.
My parameter alias i called "dec2" for this test.
I would think that it is something like this, but no luck
var val = Umbraco.Model.MacroParameters["dec2"];
or
var val = Umbraco.TypedContent(Model.Macroparameters["dec2"]);
If this still does´nt work, check your logfile. The error you pasted is just a generic error message macros usally exposes to avoid exposing sensitive code. Your /Config/Logs/ file should have more info about the error.
Lets me know if this works for you!
Great to hear that you just started using Umbraco! Welcome to a great community!
Your macro parameter simply maps to a public property of your user
control. It's a bit more convenient to start from adding a property to
the control since umbraco has a feature of determining such properties
and offers to add corresponding macro parameters automatically.
Haha i´ll hold you to that! Going to Codegarden this summer! :)
Great to hear that it worked out for you, happy i could help. Seeing that i dont usally do UserControls (usally prefer MacroPartialViews), this was quite educational for me to. So we both learned something here! :)
get macro parameter in .net usercontrol
Hi, I am new to Umbraco.
We have some legacy .net code, which we would like to use as macros. I have created the macro, and added a few parameters, and the macro can be inserted in RTE.
My question is, how do i retrieve the macro parameter value in my .net code. My parameter alias i called "dec2" for this test.
I would think that it is something like this, but no luck
or
Hope someone can guide in a direction :-)
Best regards, and thanks
Jimmy
Hi Jimmy.
Have you tried:
var dec2 = Model.MacroParameters["dec2"].ToString();
Hi Dennis
Thanks, it looks right, but still does not work, I get a
"Error loading userControl '~/usercontrols/test.ascx' 1"
Maybe my problem is that I am not sure how to use Model, and how to get a instance of it.
Should Model just be available, or do I need to import something?
Sorry, but I am quite new to Umbraco :-)
Hi again Jimmy.
What version of Umbraco are you using?
The Model object is accessible if your view inhertits Umbraco.Web.Macros.PartialViewMacroPage.
Here is a complete code for the macro partial view:
https://our.umbraco.org/documentation/reference/templating/macros/Partial-View-Macros/
If this still does´nt work, check your logfile. The error you pasted is just a generic error message macros usally exposes to avoid exposing sensitive code. Your /Config/Logs/ file should have more info about the error.
Lets me know if this works for you!
Great to hear that you just started using Umbraco! Welcome to a great community!
Thanks :-)
I am using Umbraco version 7.4.2 assembly: 1.0.5921.28477
I am not using Razor script, but plain old .net code :-)
I have looked at the log file, and I guess the the first problem is that the conrol property "dec2" "doesn't exist or aren't accessible (public)"
Sorry, i missed the fact that you are building a usercontrol and not a MacroPartialView. I never work with Usercontrols so im not much help sorry.
See this tutorial on how to use macros within a usercontrol and adding macro parameters: http://www.nibble.be/screencasts/Addingcustomusercontrols.htm
Or read this thread: https://our.umbraco.org/forum/developers/extending-umbraco/26153-Use-parameters-of-macro-with-usercontrol
Thank you so much, that worked
So simple :-)
Next time you are in Copenhagen I will buy you a beer and a pizza :-)
Best regards
Jimmy
Haha i´ll hold you to that! Going to Codegarden this summer! :)
Great to hear that it worked out for you, happy i could help. Seeing that i dont usally do UserControls (usally prefer MacroPartialViews), this was quite educational for me to. So we both learned something here! :)
Have a great day!!
Yes do that. If you come by Copenhagen, give me a shout :-)
Have a great day too!!
is working on a reply...