Help with variables in a href

Discussions about Mainlobby running on Apple mobile devices.
rileydog
Expert
Expert
Posts: 667
Joined: Wed Jun 02, 2004 12:25 am
Location: Kalamazoo, Michigan
Contact:

Help with variables in a href

Postby rileydog » Fri Sep 24, 2010 4:22 pm

I am trying to have a variable be the a href for a button - for example, if I select a zone, I have a variable that contains the html page specific to that zone (this html page contains the only options for that zone like movies, PVR, etc.).

<li class="menu"><a href={{{{clientname}}_zonescenehtml}}><img alt="Zone Media" src="images/Showtimes.png" /><span class="name">Zone Media</span><span class="arrow"></span></a></li>

Is there a way to have a button go to a page that is in a ML variable?

Thanks,

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Re: Help with variables in a href

Postby CinemarDave » Fri Sep 24, 2010 5:21 pm

Yes, but use an OnClick event and the doSwitchURL function.

Code: Select all

<li class="menu"><a href="#" onclick="doSwitchURL('{{{{clientname}}_zonescenehtml}}');"><img alt="Zone Media" src="images/Showtimes.png" /><span class="name">Zone Media</span><span class="arrow"></span></a></li>


or more simply

Code: Select all

<li class="menu"><img alt="Zone Media" src="images/Showtimes.png" /><span onclick="doSwitchURL('{{{{clientname}}_zonescenehtml}}');" class="name">Zone Media</span><span class="arrow"></span></li>

rileydog
Expert
Expert
Posts: 667
Joined: Wed Jun 02, 2004 12:25 am
Location: Kalamazoo, Michigan
Contact:

Re: Help with variables in a href

Postby rileydog » Fri Sep 24, 2010 10:13 pm

I have been fighting with this - all that is returned when I click is a "#" -- I inspected it and the doSwitchURL isn't being called. I am using:

Code: Select all

<li class="menu"><a href="#" onClick="doSwitchURL('Media-PVR.html');"><img alt="Zone Media" src="images/Showtimes.png" /><span class="name">Zone Media</span><span id="ml__{{{{clientname}}_SOURCEDESC}}" class="comment">{{{{{{clientname}}_SOURCEDESC}}}}</span><span class="arrow"></span></a></li>


I took out the variables to test - I am just trying to go to Media-PVR on a click...

The objects look perfect:
You do not have the required permissions to view the files attached to this post.

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 12:19 pm
Contact:

Re: Help with variables in a href

Postby bigDvette » Fri Sep 24, 2010 10:29 pm

Try removing the <a tag altogether and moving the onclick to the <li tag. See if that fires it off.

rileydog
Expert
Expert
Posts: 667
Joined: Wed Jun 02, 2004 12:25 am
Location: Kalamazoo, Michigan
Contact:

Re: Help with variables in a href

Postby rileydog » Fri Sep 24, 2010 10:52 pm

So close - thanks!

doSwitchURL is being called - however, the URL being return is not being substituted. I am getting Media-{{{{clientname}}_SOURCEDESC}}.html returned from the function.

And, I can't get the image to the left...

This is the code:

Code: Select all

<li class="menu" onClick="doSwitchURL('Media-'+'{'+'{'+'{'+'{clientname}'+'}_SOURCEDESC'+'}'+'}.html');"><img alt="Zone Media" src="images/Showtimes.png" /><span class="name">Zone Media</span><span id="ml__{{{{clientname}}_SOURCEDESC}}" class="comment">{{{{{{clientname}}_SOURCEDESC}}}}</span><span class="arrow"></span></li>
You do not have the required permissions to view the files attached to this post.

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 12:19 pm
Contact:

Re: Help with variables in a href

Postby bigDvette » Fri Sep 24, 2010 11:59 pm

Wait, what are you trying to do.

So when you first load the page MLSErver HTTP server parses the HTML and replaces all your variable names.

unless you define an id with the whole ml__ thing it doesn't get updated.

Now, all doSwitchURL does it load the URL you provided in to the same browser session, so it isn't going to go through the server to get this done.

What you could do is create a variable in mlserver called ZoneMediaURL and make it's value Media-{{{{clientname}}_SOURCEDESC}}.html

then change your code to

<li class="menu id="ml__ZoneMediaURL" onClick="callDoSwitchURL("ml_ZoneMediaURL")>{{ZoneMediaURL}}>.......
</li>

write a functino

function callDoSwitchURL(id) {
var url = document.getElementById(id).innerHTML;
doSwitchURL(url);
}

now your value of ml_ZoneMediaURL will get updated and your proxy to doSwitchURL will get its value. The id will never change, so you are safe.

I do this a much different way in my current libraries and have a special type of var mlurl_ where I take care of all this in jQuery syntax, but it is too complicated to explain here.

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 12:19 pm
Contact:

Re: Help with variables in a href

Postby bigDvette » Sat Sep 25, 2010 12:47 am

Oh and as for why your text is to the left of the image. I'm guessing it is because of removal of the <a tag after taking a quick look. You could put the onClick back on the <a tag since you said it was firing and it should work that way.

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Re: Help with variables in a href

Postby CinemarDave » Sat Sep 25, 2010 12:02 pm

You'll see examples of exactly what you are trying to do in the Index.html file. Just replicate what is there. Make sure you are including the correct styles.css file and not overwriting some of the styles with your own.

Code: Select all

   <li class="menu"><a href="{{any valid server variable}}"><img alt="Movies" src="images/Showtimes.png" /><span class="name">Movies</span><span id="ml__media_{{clientname}}_activezone" class="comment">{{media_{{clientname}}_activezone}}</span><span class="arrow"></span></a></li>


should work.

rileydog
Expert
Expert
Posts: 667
Joined: Wed Jun 02, 2004 12:25 am
Location: Kalamazoo, Michigan
Contact:

Re: Help with variables in a href

Postby rileydog » Sat Sep 25, 2010 1:15 pm

Thank you both very much - the issue I had was that I have a variable that itself references what I wanted - so, {{{{clientname}}_SOURCEDESC}} contains a variable which itself is what I want to use, so {{{{{{clientname}}_SOURCEDESC}}}} is what I was trying to use. With Dave's example, it returns <blank> whereas {{{{clientname}}_SOURCEDESC}} does return what I expect (but, not what I needed) -- so, I believe there may be an issue dealing with these type of variables.

Using the other example (using a function), I got that to work - however, I couldn't get the <a ref> working with it so the graphic isn't left justified.

I have a workaround whereas I am modifying all my server macros to populate a variable so I eliminate the need to use {{{{{{clientname}}_SOURCEDESC}}}} - so, I figure this is the best way to get it done. So, using Dave's example and not doing {{{{{{clientname}}_SOURCEDESC}}}} works.

But, may want to look into why {{{{{{clientname}}_SOURCEDESC}}}} returns blank when {{{{clientname}}_SOURCEDESC}} returns the correct value.

Thanks a lot for the help!

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 12:19 pm
Contact:

Re: Help with variables in a href

Postby bigDvette » Sat Sep 25, 2010 4:21 pm

Let me see if I can explain this.

Let's say {{clientname}}_SOURCEDESC resolves to PVR

When you use variable {{{{{{clientname}}_SOURCEDESC}}}} the html page parser that returns your HTML is not going to return Media-{{PVR}} or MEdia-{{{{clientname}}_SOURCEDESC}} which is what I think you believing it would. If it returne anything I think it would be the first one.

Even if it returned what you wanted the variable is not going to be resolved when you call doSwitchURL anyway, so it is a mute point.

So you have gone to using Media-'{'+'{'+'{'+'{clientname}'+'}_SOURCEDESC'+'}'+'}.html

Again, this won't do anything because what will be returned as your HTML will be
Media-{{{{clientname}}_SOURCEDESC}}.html and when you send that to the doSwitchURL it is going to literally try and load Media-{{{{clientname}}_SOURCEDESC}}.html which obviously isn't what you want.

I'm guessing what you want to do is be able to navigate to Media-PVR.html correct?

Ok, so if you were to use onClick="doSwitchURL('Media-{{{{clientname}}_SOURCEDESC}}.html');" what would be returned when you loaded this page is
onClick=doSwitchURL('Media-PVR.html') which is what you want right?

Problem here ends up being if someone else changes the Zone Media, this client will not get updated because there is no var updating the onClick command.

So what I would do is write yourself a little function like

function zoneMediaNavigate() {
var curZoneMedia = document.getElementById('zoneMedia').getElementByClassName('comment').innerHTML
doSwitchURL('Media-'+curZoneMedia+'.html');
}


change your <a tag to read
<a href="#" onClick="zoneMediaNavigate();">

change your <li tag to
<li id="zoneMedia" class="menu">

Essentially this will grab the SOURCEDESC from the <span id="ml__{{{{clientname}}_SOURCEDESC}} "> and use it to navigate.

rileydog
Expert
Expert
Posts: 667
Joined: Wed Jun 02, 2004 12:25 am
Location: Kalamazoo, Michigan
Contact:

Re: Help with variables in a href

Postby rileydog » Sat Sep 25, 2010 5:06 pm

Thanks - that is making more sense and I will give it a shot.

To give some context, I have all my zones served by all or some subset of all my centralized sources - with a combination of CAV's (audio) and a Borrego 6x6 matrix (video), I have no local sources - all are served from a central location. It gets a little more complicated because I do have some zones that are served by "real" audio receivers that are hooked to a global cache to control its' IR. And, some zones use CAV for some audio sources and the local receiver for some video sources. But, that is only a volume situation - those local receives have no other sources attached to them - they just serve my component over cat5 from the server room and all switching is done there.

All this complexity I simplified by assigning each zone 6 slots (all my zones have a maximum 6 sources, some have less). Through a generic setup scene I am able to make the mappings and assign the connections. All I have to hardcode is a single server macro per zone to define some baseline prefixes and a series of one-time associations (like Global Cache location, etc.). For example, I have 3 video (movie) servers - if I notice a zone is often conflicting with another zone (both zones watch different movies at the same time), I can go to a ML Scene and point the zone to use a different movie server without any changes to my scenes. Also, I am able to have generic volume commands and actions - I have no zone specific scenes, they are all handled using dereferenced variables.

With all that said, for this specific example, I have the following:

{{clientname}}_SOURCEDESC : contrains the ML variable for the client selected zone
{{{{clientname}}_SOURCEDESC}} : contains the clients' selected zone description

For example, if my iPhone chooses to control zone master bedroom, {{clientname}}_SOURCEDESC will contain MBR_SOURCEDESC and, assuming the master bedroom was/is set to PVR, {{MBR_SOURCEDESC}} would be PVR (or MOVIE, or XM RADIO....) -- this also handles the case where another client may change the master bedroom source - that too will keep the iPhone displaying the correct selected source.

I may have made it more complicated than I should but it I have had 4 major versions prior to this one - and this one is by far the most flexible I have developed with the least amount of scenes. I don't like interfaces that start at the media - to me, the zone drives all decisions - without a zone, media has no context - so, I always start my media with zone first, then display your options from there. With this, I don't need to instruct any of the lobby products where to have action - once a zone is selected, all the dereferences are passed to DVDlobby. XMlobby, etc... No additional setup screens or specialized scenes per zone.

Hopefully that sheds some light as to why I am doing this craziness. Thanks again for all your help!

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Re: Help with variables in a href

Postby CinemarDave » Sun Sep 26, 2010 1:38 pm

I cannot come up with any easy mechanism for resolving a double reference to a server variable. However if you can break out your zone source into a single server variable then look at the following code. In particular look at the new LoadPageByID function and the hidden <SPAN> holding the reference. The first <LI> in the list shows how to use all of this in a <A> anchor.

[code]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<link href="images/MainLobby.png" rel="apple-touch-icon" />
<meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" />
<link href="css/styles.css" rel="stylesheet" media="screen" type="text/css" />
<script src="javascript/functions.js" type="text/javascript"></script>
<script src="javascript/iPhone.js" type="text/javascript"></script>
<title>MainLobby for the iPhone/iTouch</title>

<script>
function StartupMacro() {
doCommand('MLConditional|IsNE##{{{{clientname}}_web_init}}##1##Macro|' +
'SetVariableFast|movies_showallcontent_{{clientname}}~1!' +
'SetVariableFast|movies_similarinit_{{clientname}}~0!' +
'SetVariableFast|movies_thumbsinit_{{clientname}}~0!' +
'SetVariableFast|{{clientname}}_web_init~1##SetVariableFast|{{clientname}}_mediasource~Movies');
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

function LoadPageByID(ID) {
var el = document.getElementById(ID);
var url = el.innerHTML + ".html";
window.location = url;
}
</script>
</head>
<body>
<div id="topbar" class="black"><div id="title">MainLobby</div>
<div id="bluerightbutton"><a href="About.html">About</a></div>
</div>

<div id="content">
<ul class="pageitem">
<li class="menu"><a href="javascript:LoadPageByID('ml__{{clientname}}_mediasource')"><img alt="Movies" src="images/Showtimes.png" /><span class="name">Movies</span><span id="ml__media_{{clientname}}_activezone" class="comment">{{media_{{clientname}}_activezone}}</span><span class="arrow"></span></a></li>
<li class="menu"><a href="Music.html"><img alt="Music" src="images/midomi.png" /><span class="name">Music</span><span id="ml__music_activemusicsourcename_{{clientname}}" class="comment">{{music_activemusicsourcename_{{clientname}}}}</span><span class="arrow"></span><span class="arrow"></span></a></li>
<li class="menu"><a href="Satellite.html"><img alt="Satellite" src="images/vocals.png" /><span class="name">Satellite Radio</span><span id="ml__mlsatradio_activeradio_alias_{{clientname}}" class="comment">{{mlsatradio_activeradio_alias_{{clientname}}}}</span><span class="arrow"></span></a></li>
<li class="menu"><a href="Security.html"><img alt="Security" src="images/password.png" /><span class="name">Security</span><span class="arrow"></span></a></li>
<li class="menu"><a href="Climate.html"><img alt="Climate" src="images/converter.png" /><span class="name">Climate</span><span class="arrow"></span></a></li>
<li class="menu"><a href="Lighting.html"><img alt="Lighting" src="images/lighting.png" /><span class="name">Lighting</span><span class="arrow"></span></a></li>
<li class="menu"><a href="Energy.html"><img alt="Energy" src="images/NES.png" /><span class="name">Energy</span><span class="arrow"></span></a></li>
<li class="menu"><a href="Weather.html"><img alt="Weather" src="images/weather.png" /><span class="name">Weather</span><span class="arrow"></span></a></li>
</ul>
</div>
<span style="visibility:hidden;" id="ml__{{clientname}}_mediasource">{{{{clientname}}_mediasource}}</span>
<p>&nbsp;</p>
<script language="javascript">
autoupdate = false;
pagevars = getvars();
StartupMacro();
</script>
</body>
</html>
[/code>


Return to “MainLobby on iPhone, iPod Touch”

Who is online

Users browsing this forum: No registered users and 1 guest