Insert flash video after a certain amount of characters
Hi, I am running an Umbraco V4 website and I have created an XSLT to display a flash movie (if one has been added to the node). The problem I have is I want to add it in the middle of the text. I was hoping I could do this automatically so that the end user doesn't have to worry about it, they can just select a movie for that node then on the page it would display after the first 200 characters or so and then the text would carry on after it. If this is not possible the other option would be that they insert the macro into the rich text editor where they want it (although I have tried this and for some reason the video player doesn't display). My last resort is to have two rich text areas for each node, one that is displayed above movie and one that is displayed below but I would prefer to avoide this if possible. Can anyone offer any suggestions as to how I could achieve my first goals? Many thanks
Here's how I would do it. Do bear in mind that my XSLT skills are better than my c# skills so I would opt for an xslt macro. But if you're more comfortable using .net then do that. The idea is the same either way.
Right now you probably have a template that has an <umbraco:Item field="bodyText" .../> and maybe a macro call to insert the video <umbraco:Macro .../>.
What you want to do is create a macro that does both of these things at the same time. You can use your existing video macro as a starting point by copying the xslt for the macro, creating a new macro (let's call it 'videoInContent') and paste the xslt from your existing video macro into it.
Rename the <template match="/"> line to make it a named template instead. A named template is kind of like a function call in other languages. Let's call it 'InsertVideo'. The line then becomes, <template name='InsertVideo">. We now have the code to insert the video.
Now we need to add some logic about when to insert the video.
The basic logic would go something like this...
<xsl:template match="/"> <xsl:choose> <xsl:when test="count($currentPage/data[@alias='bodyText']) > 200"> <!-- show the first 200 characters of the bodyText property, plus any additional characters until we get to whitespace, being sure we're not in the middle of a tag, such as an <a> tag --> <xsl:call-template name="videoInContent" /> <!-- show the remaining characters in the bodyText property --> </xsl:when>
The only really challenging thing is the code to perform the action of the first comment. XSLT is not really wonderful at string handling. It can be done but it is a bit verbose, using a recursive template or two.
If you need help with that bit of the code give a shout. There are lots of XSLT masters on the forum that can help. If I can dig out some code that does something similar I will.
Alternatively, you could write the entire macro in .net, including the video insertion code. The string handling would certainly be easier in c# if your familiar with it.
Thanks for the response, I think that is the bit I will have trouble with, making it so that it doesn't cut off have way through a sentence or tag. I am definately not an asp.net developer so it would have to be XSLT for me. I would appreciate it if you could give me some help on the missing bits of code from your example. Many thanks.
Insert flash video after a certain amount of characters
Hi, I am running an Umbraco V4 website and I have created an XSLT to display a flash movie (if one has been added to the node). The problem I have is I want to add it in the middle of the text. I was hoping I could do this automatically so that the end user doesn't have to worry about it, they can just select a movie for that node then on the page it would display after the first 200 characters or so and then the text would carry on after it. If this is not possible the other option would be that they insert the macro into the rich text editor where they want it (although I have tried this and for some reason the video player doesn't display). My last resort is to have two rich text areas for each node, one that is displayed above movie and one that is displayed below but I would prefer to avoide this if possible. Can anyone offer any suggestions as to how I could achieve my first goals? Many thanks
Here's how I would do it. Do bear in mind that my XSLT skills are better than my c# skills so I would opt for an xslt macro. But if you're more comfortable using .net then do that. The idea is the same either way.
Right now you probably have a template that has an <umbraco:Item field="bodyText" .../> and maybe a macro call to insert the video <umbraco:Macro .../>.
What you want to do is create a macro that does both of these things at the same time. You can use your existing video macro as a starting point by copying the xslt for the macro, creating a new macro (let's call it 'videoInContent') and paste the xslt from your existing video macro into it.
Rename the <template match="/"> line to make it a named template instead. A named template is kind of like a function call in other languages. Let's call it 'InsertVideo'. The line then becomes, <template name='InsertVideo">. We now have the code to insert the video.
Now we need to add some logic about when to insert the video.
The basic logic would go something like this...
That should make some sense, I hope.
The only really challenging thing is the code to perform the action of the first comment. XSLT is not really wonderful at string handling. It can be done but it is a bit verbose, using a recursive template or two.
If you need help with that bit of the code give a shout. There are lots of XSLT masters on the forum that can help. If I can dig out some code that does something similar I will.
Alternatively, you could write the entire macro in .net, including the video insertion code. The string handling would certainly be easier in c# if your familiar with it.
cheers,
doug.
i am new to umbraco and only have limited xslt experience. i have used a version of the template below to strip out html tags from rich text:
<xsl:template name="StripHTML">
<xsl:param name="HTMLText"/>
<xsl:choose>
<xsl:when test="contains($HTMLText, '<')">
<xsl:call-template name="StripHTML">
<xsl:with-param name="HTMLText" select="concat(substring-before($HTMLText, 'LT_SIGN'),
substring-after($HTMLText, 'GT_SIGN'))"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$HTMLText"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
this would allow you to strip down to text, it should be quite easy then to split the copy.
this may not be exactly what you need to do, as you will want to maintain the html, and also the movie may need to appear in the right place[?]
i have also previously put a custom tag in the editor which you can then replace out in the xslt
sorry if that's actually not too much help, i can have a look at work tomorrow if nobody comes up with anything in the mean time.
blimey - trust doug to come up with the goods while i am writing, just ignore me
Hi Doug,
Thanks for the response, I think that is the bit I will have trouble with, making it so that it doesn't cut off have way through a sentence or tag. I am definately not an asp.net developer so it would have to be XSLT for me. I would appreciate it if you could give me some help on the missing bits of code from your example. Many thanks.
is working on a reply...