I have an object of IPublishedContent called 'product'.
I can access its 'productCategory' property as follows:
GetPropertyValue<string>("productCategory")
The product category is a value assigned by a dropdown menu used in the content page when creating the product page.
I have another property, the product description, called 'productDescription' - which is a macro rather than a simple dropdown. This macro has two fields within it, a subheading and a description. I want to just access the description text field.
I don't know what the syntax is or what functions I can use (GetChildProperties is just a made up example of what I'd like).
Lastly, it may be useful to note that if I use the same code as I did for category but for description instead (seen below), the following output is produced. I would just want to access the description section of this.
product.GetPropertyValue<string>("productDescription")
// Produces output:
<h2>Product Y Subheading</h2> <div class="zip-divder"></div<p>Product Y Description</p>
If you have a look at your Macro in the backoffice, you will see there are four ways of 'implementing it'.
The current favoured approach is to use a PartialViewMacro, if this is the case in your scenario you should have a corresponding razor partial in PartialViewMacroFiles (Developer section), and in this file you should find the implementation that produces the markup
<h2>Product Y Subheading</h2> <div class="zip-divder"></div<p>Product Y Description</p>
If you are looking to change the output of the Macro, then update it here.
You can access the Macro Parameters in this file using GetParameterValue from the Umbraco.Web.Models namespace eg
@using Umbraco.Web.Models
@{
var mediaId = Model.GetParameterValue<string>("mediaId","somedefaultvalue");
}
Macros are designed to render out a particular layout for a set of parameters in the context of the page they are rendered on.
So I have a feeling that if you have a scenario where you want to read the parameters entered into a Macro. outside of its associated Partial View Macro then using a Macro, might not be the best way to manage that content!
Eg. I need to understand more about your scenario and what you are trying to output to know why product description needs to be in a Macro?
Accessing a property's macro's fields
Hey,
I have an object of IPublishedContent called 'product'.
I can access its 'productCategory' property as follows:
The product category is a value assigned by a dropdown menu used in the content page when creating the product page.
I have another property, the product description, called 'productDescription' - which is a macro rather than a simple dropdown. This macro has two fields within it, a subheading and a description. I want to just access the description text field.
So in pseudo, I'm imagining something like:
I don't know what the syntax is or what functions I can use (GetChildProperties is just a made up example of what I'd like).
Lastly, it may be useful to note that if I use the same code as I did for category but for description instead (seen below), the following output is produced. I would just want to access the description section of this.
Any help appreciated, cheers.
Conor
Hi Conor
GetPropertyValue
If you have a look at your Macro in the backoffice, you will see there are four ways of 'implementing it'.
The current favoured approach is to use a PartialViewMacro, if this is the case in your scenario you should have a corresponding razor partial in PartialViewMacroFiles (Developer section), and in this file you should find the implementation that produces the markup
If you are looking to change the output of the Macro, then update it here.
You can access the Macro Parameters in this file using GetParameterValue from the Umbraco.Web.Models namespace eg
Macros are designed to render out a particular layout for a set of parameters in the context of the page they are rendered on.
So I have a feeling that if you have a scenario where you want to read the parameters entered into a Macro. outside of its associated Partial View Macro then using a Macro, might not be the best way to manage that content!
Eg. I need to understand more about your scenario and what you are trying to output to know why product description needs to be in a Macro?
regards Marc
is working on a reply...