I have a macro tied to a PartialViewMacroPage and I have parameters set at the macro level that I'm trying to get the value from in the PartialViewMacroPage.
When I add the macro using the rich editor, I'm setting parameters.
I can get as far as identifying if it's there but it trying to access the value and it comes up empty.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
var galParam = Model.MacroParameters["galleryWidth"];
<script type="text/javascript">
var test = "@galParam" //empty
</script>
If I check the html in the rich editor I can see the parameter values present and the values I set.
I only have some experience with macros, so I thought I could give you my suggestion. I have integrated a macro for image carousel in Umbraco (Bootstrap), where I have a parameter with name 'SliderData' that I refer to in this way:
But the type isn't a Textbox, it's a integrated data type with name 'simple slider editor' (from a Property editor named SimpleSliderEditor), and this applies of course to more values in a matrix than a single value, but maybe it can put you on an idea of how to solve your task?
However, in another example of a macro I have with values from two Textboxes, are using XSLT (which I did not like, but it works), and I get the parameters' location' and' height' with this code:
I'm a little unsure what you mean. I have used XSLT method for inserting an iframe as a macro in the grid, where I can insert GoogleMyMaps. The values do I then enter together with the content, then I save content in the grid, and the map with the entered values (in my xlst-codes the two parameters 'location' and 'height') display properly on the page.
I'm not debating your code. I believe the xslt works though I haven't tried it yet.
I'm just not crazy about switching to XSLT. I feel that razor is easier to look at which is why I'm bummed I can't find a working example or documentation that makes sense how to target the parameter in a PartialViewMacroPage in Razor.
Between razor and XSLT, its super simple to just have Model.MacroParameters ["whatever"].
Why one works but not the other doesn't make sense despite using the same snippet.
For anyone who has a similar problem. I could find the problem.
All params of aspecific Macro should be declared in the macro admin.
I am using Umbraco 8.1 and to do this you:
1. Go to Settings
2. Click on Macros
3. Click on the Macro you want to add the params to
4. on the upright corner there is a burger menu with the label "Parameters"
You are welcome.
It is so annoying that the docs are so short and not clear most of the time. One of the downsides of Umbraco I guess.
Passing a variable to a PartialViewMacroPage
I have a macro tied to a PartialViewMacroPage and I have parameters set at the macro level that I'm trying to get the value from in the PartialViewMacroPage.
When I add the macro using the rich editor, I'm setting parameters.
I can get as far as identifying if it's there but it trying to access the value and it comes up empty.
If I check the html in the rich editor I can see the parameter values present and the values I set.
What else do I need to check or add to make this work?
I only have some experience with macros, so I thought I could give you my suggestion. I have integrated a macro for image carousel in Umbraco (Bootstrap), where I have a parameter with name 'SliderData' that I refer to in this way:
And in the same page, I get my data as follows:
But the type isn't a Textbox, it's a integrated data type with name 'simple slider editor' (from a Property editor named SimpleSliderEditor), and this applies of course to more values in a matrix than a single value, but maybe it can put you on an idea of how to solve your task?
However, in another example of a macro I have with values from two Textboxes, are using XSLT (which I did not like, but it works), and I get the parameters' location' and' height' with this code:
Thanks Tom. None of that code will work so long as
Model.MacroParameters ["whatever"] returns empty. I feel like there is an extra step somewhere that isn't obvious.
This should also be documented somewhere too. How to tie a parameter on a macro to a partialpageview not just for xslt but for razor too.
I'm a little unsure what you mean. I have used XSLT method for inserting an iframe as a macro in the grid, where I can insert GoogleMyMaps. The values do I then enter together with the content, then I save content in the grid, and the map with the entered values (in my xlst-codes the two parameters 'location' and 'height') display properly on the page.
Original Source
I'm not debating your code. I believe the xslt works though I haven't tried it yet.
I'm just not crazy about switching to XSLT. I feel that razor is easier to look at which is why I'm bummed I can't find a working example or documentation that makes sense how to target the parameter in a PartialViewMacroPage in Razor.
Between razor and XSLT, its super simple to just have Model.MacroParameters ["whatever"].
Why one works but not the other doesn't make sense despite using the same snippet.
For anyone who has a similar problem. I could find the problem.
All params of aspecific Macro should be declared in the macro admin.
I am using Umbraco 8.1 and to do this you: 1. Go to Settings 2. Click on Macros 3. Click on the Macro you want to add the params to 4. on the upright corner there is a burger menu with the label "Parameters"
You are welcome.
It is so annoying that the docs are so short and not clear most of the time. One of the downsides of Umbraco I guess.
is working on a reply...