As this parameter sets the page context, you could get its value from @Model.Id in your Razor script (assuming you are using a Razor Macro rather than Mvc)
Yup, you are right it is odd, DynamicNode used for @Model is bypassing this context parameter, the RenderMacroContent method was written long before Razor of course.
So I just did a quick POC and the workaround is to create a macro parameter and to retrieve that value in your Razor instead:
Get page id in razor macro
Hi guys.
Razor macro is called from XSLT tempalte like this:
<xsl:value-of select="umbraco.library:RenderMacroContent($razorMacro, $nodeId)" />
How do I then retrieve $nodeId parameter in Razor?
Hi Ivan,
As this parameter sets the page context, you could get its value from @Model.Id in your Razor script (assuming you are using a Razor Macro rather than Mvc)
Hope that helps you?
Thanks,
Jeavon
Hi Jeavon.
Nope, it does't work for me. Model.Id always returns Id of current page. Perhaps I'm using Razor Mvc (or whatever it is). Any other thoughs?
Yup, you are right it is odd, DynamicNode used for @Model is bypassing this context parameter, the RenderMacroContent method was written long before Razor of course.
So I just did a quick POC and the workaround is to create a macro parameter and to retrieve that value in your Razor instead:
In my XSLT:
<xsl:variable name="nodeId">1053</xsl:variable>
<xsl:value-of select="umbraco.library:RenderMacroContent(concat('<?UMBRACO_MACRO macroAlias="testRazor" nodeId="',$nodeId,'"></?UMBRACO_MACRO>'),$nodeId)" disable-output-escaping="yes"/>
In my Razor:
<p>Parameter Id: @Parameter.nodeId</p>
You must add the nodeId parameter to your Macro definition also.
Hopefully that will do the trick?
Alright. Thanks, Jeavon. I'll give it a try.
is working on a reply...