As I noob, I tried to create a teaser using Razor, so I could embed some shortened text of a certain page on the homepage, together with a 'read more' button.
Here's how I tried to do it:
I got a node called 'Over ons' (About us) with an ID of 1204
I put this node into a variable called 'Overons'
I now need to extract the property (or alias) 'tekstOverOns' from it, for which I use the 'Value.ToString()' code
This works ALMOST, since it's putting ALL of the text from 'tekstOverOns' into the teaser, including all HTML tags (like <p>, <br>, etc) which I don't need.
What I DO need is something like @Overons.GetProperty("tekstOverOns").InnerText, because my experience is that my code in this way just outputs plain text (which is all I want) instead of HTML.
Unfortunately, as far as I can see 'InnerText' only works for CHILDREN ('items') of a node, used in a 'for-each'-loop. And since my 'Over ons' (About us) page doesn't have any children, it doesn't work.
Okay, so I got this far:
@{ var Overons = @Model.NodeById(1204); <p> @Overons.GetProperty("tekstOverOns").Value.ToString(); </p> }
But this outputs the next line of text and tags:
<p>JP Flooring staat al jarenlang garant voor kwaliteitsvloeren en designmaatwerk. <br /><br /> Uiteraard biedt JP Flooring ook ruime keuze voor de perfecte afwerking van plinten, dorpels, architraven, en convectorroosters.</p>
Instead, I just need
JP Flooring staat al jarenlang garant voor kwaliteitsvloeren en designmaatwerk. Uiteraard biedt JP Flooring ook ruime keuze voor de perfecte afwerking van plinten, dorpels, architraven, en convectorroosters.
(without the HTML tags surrounding and distorting my text)
Any solutions for this problem?
Oh, and after this one is solved I will try to go and use some 'trim' function to make a teaser of it, and if I can't figure this out, I might come back here for some more advice ;-) But not before I REALLY tried it, off course.
Awesome, glad things are working out for you. I'm guessing that you just need to add a ToString(), since I believe StripHTML() still returns an HTMLString object:
@{ var overons =Library.NodeById(1204); @uComponents.Core.XsltExtensions.Strings.GetFirstWords(Library.StripHtml(overons.tekstOverOns).ToString(),10,"..."); }
Wait, I have one more question (just to create something AMAZING instead of just super):
How can I BREAK words using this script?
I mean, here's the idea: there's a column with justified alignment for its text. This column contains the teaser you just helped me to build. But this column only contains FULL words, none of it are EVER broken up!
Example sentence (current, WRONG state):
This is the end of a line, but unfortunately it doesn't break right.
Example sentence (future, RIGHT state):
This is the end of a line, but unfor- tunately it doesn't break right.
Do you see how 'unfortunately' gets broken up when coming to the end of the line? How can I achieve this in my code (see your own example above)?
Whenever I am Googling I just see those people having problems with lines like ThisSentenceDoesn'tContainAnySpaces, where this long word needs to be broken into several separated words.
Creating a news teaser
As I noob, I tried to create a teaser using Razor, so I could embed some shortened text of a certain page on the homepage, together with a 'read more' button.
Here's how I tried to do it:
Okay, so I got this far:
But this outputs the next line of text and tags:
<p>JP Flooring staat al jarenlang garant voor kwaliteitsvloeren en designmaatwerk. <br /><br /> Uiteraard biedt JP Flooring ook ruime keuze voor de perfecte afwerking van plinten, dorpels, architraven, en convectorroosters.</p>
Instead, I just need
JP Flooring staat al jarenlang garant voor kwaliteitsvloeren en designmaatwerk. Uiteraard biedt JP Flooring ook ruime keuze voor de perfecte afwerking van plinten, dorpels, architraven, en convectorroosters.
(without the HTML tags surrounding and distorting my text)
Any solutions for this problem?
Oh, and after this one is solved I will try to go and use some 'trim' function to make a teaser of it, and if I can't figure this out, I might come back here for some more advice ;-) But not before I REALLY tried it, off course.
Thanks in advance!
You're very close. Umbraco has a helper method that strips the HTML, which is probably what your looking for:
To truncate the text, have a look at this recent post which has some good suggestions.
Great, thanks a lot!!!
Okay, now I got both stripHtml and truncating seperately from each other working fine.
How do I combine those two?
This is my (in my head) logical combi which gives me an error:
And again I know I'm so close I can almost smell it!!! :-D
PS: for the record: I also installed uComponents with just the 'string' option checked for XSLT, is that enough?
Awesome, glad things are working out for you. I'm guessing that you just need to add a ToString(), since I believe StripHTML() still returns an HTMLString object:
Yes!!! Thanks Douglas!
Heh, heh. No problem! ;)
Wait, I have one more question (just to create something AMAZING instead of just super):
How can I BREAK words using this script?
I mean, here's the idea: there's a column with justified alignment for its text.
This column contains the teaser you just helped me to build.
But this column only contains FULL words, none of it are EVER broken up!
Example sentence (current, WRONG state):
This is the end of a line, but
unfortunately it doesn't break right.
Example sentence (future, RIGHT state):
This is the end of a line, but unfor-
tunately it doesn't break right.
Do you see how 'unfortunately' gets broken up when coming to the end of the line?
How can I achieve this in my code (see your own example above)?
Whenever I am Googling I just see those people having problems with lines like
ThisSentenceDoesn'tContainAnySpaces, where this long word needs to be broken
into several separated words.
Do you know a solution for this?
is working on a reply...