Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
<txp:yield> and JW Player... how to create a unique ID
I’m more than a little happy that the <txp:yield> tag has been added to Textpattern because of the new ability to integrate scripts and software without the need for plugins, but there are still challenges.
I’ve produced a form to launch JW Player, but have a minor issue creating a unique element ID to attach the player to. Here is my sample form:
<script type='text/javascript' src='mediaplayer/swfobject.js'></script>
<span id='mediaspace'>Play file <txp:yield /></span>
<script type='text/javascript'>
var so = new SWFObject('mediaplayer/player.swf','ply','470','24','9','#000000');
so.addParam('allowfullscreen','true');
so.addParam('allowscriptaccess','always');
so.addParam('wmode','opaque');
so.addVariable('file','audiofiles/<txp:yield />');
so.write('mediaspace');
</script>
and is called with
<txp:output_form form="jw_player">Filename</txp:output_form>
It works by calling the player to replace the element ID=‘mediaspace’. The problem is that I need a different ID for each file I want to play, otherwise subsequent files I try and play on the same page won’t work.
My make-shift solution was to give the element an ID=’<txp:yield />’, but this has the drawback that my filename has to comply with the ID naming standards (e.g. no spaces, no periods), and is not easy to enforce. Is there a more elegant solution?
Stuart
Offline
Re: <txp:yield> and JW Player... how to create a unique ID
Hi stuart
It would good if txp:yield can handle more than one attribute (toc toc bloke can you do that with some magic ;) )
How if you use a txp:variable like this.
<txp:variable name="myid" value="mediaspace1" />
<txp:output_form form="jw_player">Filename</txp:output_form>
and put your form lik this :
<script type='text/javascript' src='mediaplayer/swfobject.js'></script>
<span id='<txp:variable value="myid" />'>Play file <txp:yield /></span>
<script type='text/javascript'>
var so = new SWFObject('mediaplayer/player.swf','ply','470','24','9','#000000');
so.addParam('allowfullscreen','true');
so.addParam('allowscriptaccess','always');
so.addParam('wmode','opaque');
so.addVariable('file','audiofiles/<txp:yield />');
so.write('<txp:variable name="myid" />');
</script>
Offline
Re: <txp:yield> and JW Player... how to create a unique ID
I agree that support for multiple attributes would be ideal, although I suppose you could set multiple variables and then call each in the appropriate place on the form.
In any case, your suggestion is certainly a better workaround than my existing one (excluding your error in the second line of your revised code), even if it requires my users to enter an extra line of code in their articles (something I’m trying to avoid where I can).
Tragically, the player appears to have broken with the change (although I’m 95% sure that this is coincidental – going back to the old code leaves it equally as broken and the code it outputs appears flawless), but I’ll take that to the player’s forum .
Thanks for your help.
Stuart
Offline
#4 2010-09-23 22:35:40
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: <txp:yield> and JW Player... how to create a unique ID
phual wrote:
My make-shift solution was to give the element an ID=’<txp:yield />’, but this has the drawback that my filename has to comply with the ID naming standards (e.g. no spaces, no periods)
Wild idea (using rah_replace):
<span id="<txp:rah_replace from=" ,." to=","><txp:yield /></txp:rah_replace>">Play file <txp:yield /></span>
Offline
Re: <txp:yield> and JW Player... how to create a unique ID
Interesting suggestion. There is the minor issue that they may use a number to start the file name (the files are recordings from different meetings, so may be names by their dates), but telling them no is easier than explaining (and getting them to remember) the <txp:variable> tag.
Although, I guess that there is no reason I can’t prefix the ID with a string and bypass that problem altogether:
<span id="fishcake<txp:rah_replace from=" ,." to=","><txp:yield /></txp:rah_replace>">Play file <txp:yield /></span>
(at least I think that works)
Thanks!
Stuart
Offline