Using variable in URL=
Using variable in URL=
I searched and did not find anything related to this. I would like to use a variable in the url= section of the menu. I am going to set a variable equal to the current date and I want a current weeks news to open that file according to the date. Is is possible to use a variable in the url=, if so are there any special quotes or anything that need to be used? Thanks,
The aI() function is used to create a menu item. The paramted passed to that funtion when you define an item is a string (like "text=item text;url=http://www.whatever.com;"). In most examples you see the parameter passed to aI() is a literal string (text inside of quotes). But you can also do string concatenation to produce the single parameter from any combination of literals, string variables, and functions that return strings.
So, at the top of your menu_data.js file, you could make a function that builds a four digit string representing the month and day (mmdd), incorporate that into a url, then return the entire url. Like so.
You could then incorporate the returned url into the aI() parameter by calling that function part way through building the string for the aI() parameter, like so:
For today, the menu item above would have a url pointing to:
Hope that helps,
Kevin
So, at the top of your menu_data.js file, you could make a function that builds a four digit string representing the month and day (mmdd), incorporate that into a url, then return the entire url. Like so.
Code: Select all
function getNewsURL()
{
var currentDate = new Date();
var currentMonth = currentDate.getMonth() + 1
if (currentMonth < 10) currentMonth = "0" + currentMonth;
var currentDay = currentDate.getDate();
if (currentDay < 10) currentDay = "0" + currentDay;
var newsURL = "http://www.newstuff.com/news/" + currentMonth + currentDay + ".pdf";
return newsURL;
}
Code: Select all
aI("text=News of the Day;url=" + getNewsURL() + ";status=Read the news;");
Code: Select all
http://www.newstuff.com/news/0811.pdf
Kevin