I have a razor script which will display members names based on a parameter (i.e sectionID). The user can insert the script and specify the section via the node tree.
I want to use it a little differently by using the script in a template and would like to pick up the secitonID based on the current seciton the user is in...so i guess my question is how to I pass the sectionID to the script when the page loads?
Assuming that is SectionId was a propertry of the page you were on you would know know to extract it ... here is soem razor that navigates back up the tree and find the first parent with the property sectionId
no worries it’s the way a write them, confusing!
Essentially all I need to know is how to pass a parameter into a macro and ensure the parameter the page id on the page that the macro is currently on...
Get page ID of current section
I have a razor script which will display members names based on a parameter (i.e sectionID). The user can insert the script and specify the section via the node tree.
I want to use it a little differently by using the script in a template and would like to pick up the secitonID based on the current seciton the user is in...so i guess my question is how to I pass the sectionID to the script when the page loads?
Cheers,
S
Assuming that is SectionId was a propertry of the page you were on you would know know to extract it ... here is soem razor that navigates back up the tree and find the first parent with the property sectionId
@foreach (var item in Model.AncestorOrSelf(1).Children.Where("Visible" )) {
if(Model.IsDescendantOrSelf(item) )
{
if(item.sectionId.GetType() != typeof(DynamicNull))
{
@item.Name
}
}
alternatively you could check for the prpoerty by using
if(item.HasProperty("sectionName")){
@item.Id
}
Opps on rereading your post I thing i may have misunderstood what you were gettting at ............ maybe this more what you are after
http://our.umbraco.org/forum/developers/razor/19040-Working-with-members-and-Razor
no worries it’s the way a write them, confusing!
Essentially all I need to know is how to pass a parameter into a macro and ensure the parameter the page id on the page that the macro is currently on...
Incase anyone wants to know it turned out to be really simple!
<umbraco:Macro ServiceType="[#pageID]" Alias="tmStaffSimple" runat="server"></umbraco:Macro>
Can i mark this as the answer?
S
do you simply mean
@Model.Id where thsi returns the page Node Id of the current page ?
Not Sure why you want to pass the PageId or any other page property when you can read them directly from your razor script?
Sorry Anthony, I am in fact using a user control and not a razor script, head is firmly up my arse! All working the way i want to now.
Thanks for your input.
S
To read page properties direct in a usercontrol without passing you can do the following
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using umbraco.NodeFactory ;
protected void Page_Load(object sender, EventArgs e)
{
_nameLabel.Text = GetPropertyFromAlias("contactNameLabel");
}
private static string GetPropertyFromAlias(string alias)
{
return Node.GetCurrent().GetProperty(alias) != null
? Node.GetCurrent().GetProperty(alias).Value
: string.Empty;
}
I am sure you get the idea from the snippets above
These are taken out Sebastiaan Janssen contact form http://our.umbraco.org/projects/website-utilities/cultiv-legacy-contact-form-(pre-47!)
is working on a reply...