Hi Barn, Yeh like Jay says Razor is .NET so you are best using the .NET API's to manipulate the string.
This snippet is untested but should give you an idea about how I would approach if needed to.
@{//Grab our property from the current page and put into a string object to work withstring myString = Model.myProperty;
//Get the character position number of first opening <p> and first closing </p>int charPositionStart = myString.IndexOf("<p>");
int charPositionEnd = myString.IndexOf("</p>");
int lengthOfText = charPositionEnd - charPositionStart;
//Substring works by passing in two numbers//First being the number of the character you want to start from//Second is the length of text to grab/output
myString = myString.Substring(charPositionStart, lengthOfText);
}
Say your current page has child nodes of the document type alias of 'post' it could have one child 'post' node or twenty. So we have got no easy way to get the value you want from that selector you done.
I presume this page has one child node of the type 'post', if so you can ammend that line to the following:
string myString = Model.post.First().myProperty;
What this does instead is says select the first child node of the document type alias of 'post' and fetch the value from the property alias 'myProperty'
This is a pretty old thread, but it's a really good match with what I am struggling with so here it goes!
I have a doc type with a bundle of properties of type textstring - they contain any number of name value pairs in up to 30 slots (specification01 - specification30).
The original data is bulk loaded with a pipe seperating the name|value i.e. Weight|10.6g -- currently I use a bit of xslt to split that up for rendering on the page.
<xsl:value-of select="substring-before(.,'|')"/>
<xsl:value-of select="substring-after(.,'|')"/>
I am wanting to use Razor on this project and I am keen to find out if there is a similar means of splitting the data from each side of the pipe to display in my page.
I am using inline razor macros for other Razor stuff whilst getting up to speed, so any ideas on that would be really helpful.
Hoping that something along the following lines may be possible?
substring-before substring-after
Hello,
I previously used the following XSLT to grab everything between the first <p> tags of my bodyText property.
Could anyone enlighten me as to how this might be done with Razor?
Cheers,
Barney
Hi Barney,
You could try the "RemoveFirstParagraphTag" function from "umbraco.library"?
Might be able to swap out the "@umbraco.library" with "@Library"? (Haven't tried that myself yet)
Cheers, Lee.
Hi Lee, cheers for the post. Doesn't appear to work though.... hmmm. Going to have a dig around...
razor is just c# so I guess you can use any .net library (including regex).
Try this to get the first paragraph:
Hi Barn,
Yeh like Jay says Razor is .NET so you are best using the .NET API's to manipulate the string.
This snippet is untested but should give you an idea about how I would approach if needed to.
Hi Wazza, cheers for this.
I'm struggling to pick up the value of "myProperty" if it belongs to a Child of the current page (Model).
I tried adding the doctypename as follows but it bombs..
Any further ideas?
Thanks,
Barn
Hi Barn,
I will explain why that will not work.
Say your current page has child nodes of the document type alias of 'post' it could have one child 'post' node or twenty. So we have got no easy way to get the value you want from that selector you done.
I presume this page has one child node of the type 'post', if so you can ammend that line to the following:
What this does instead is says select the first child node of the document type alias of 'post' and fetch the value from the property alias 'myProperty'
Hope this helps mate.
Warren
Hi guys,
This is a pretty old thread, but it's a really good match with what I am struggling with so here it goes!
I have a doc type with a bundle of properties of type textstring - they contain any number of name value pairs in up to 30 slots (specification01 - specification30).
The original data is bulk loaded with a pipe seperating the name|value i.e. Weight|10.6g -- currently I use a bit of xslt to split that up for rendering on the page.
I am wanting to use Razor on this project and I am keen to find out if there is a similar means of splitting the data from each side of the pipe to display in my page.
I am using inline razor macros for other Razor stuff whilst getting up to speed, so any ideas on that would be really helpful.
Hoping that something along the following lines may be possible?
As ever, many thanks for any advice you can give.
Cheers
Ben
is working on a reply...