SALSA Template Script to generate dynamic titles


/ Published in: JavaScript
Save to your folder(s)

This was developed for 1Sky to write out titles to the template. Thsi signle template can handle many DIA pages. (Donation, Action, TAF). It can determine what kind of page it is on by reading the URL and can even handle short URLs


Copy this code and paste it in your HTML
  1. <?
  2. var theTitle = "Join more than 216,249 Americans who want bold action on climate change.";
  3.  
  4. var tracking_code = salsa.getParameter("code");
  5. if(tracking_code == "") tracking_code = 'none';
  6.  
  7. //this gets some parameters from the URL
  8.  
  9. function getTitle(){
  10.  
  11. var where = Request.getURI() ;
  12. var match = /[a-zA-Z0-9\-]+$/i.exec(where);
  13.  
  14. if(match != null) {
  15. var shorturl = /[a-zA-Z0-9\-]+$/i.exec(where);
  16. var orderBy = 'Last_Modified DESC';
  17. var conditions = [ new Condition('slug', 'IN', shorturl)];
  18. var items = db.getObjects('publish', conditions, orderBy);
  19. for each (item in items) {
  20. var table = db.getObject('database_table', item.database_table_KEY);
  21. var ref = db.getObject(table.table_name, item.table_KEY);
  22. print(ref.Reference_Name);
  23. }
  24. } else {
  25. var lists =Request.getParameterList();
  26. for each (list in lists) {
  27. if(list.name == 'action_KEY'){
  28. var camp=db.getObject("action",list.value);
  29. print(camp.Reference_Name);
  30. } else if(list.name == 'donate_page_KEY') {
  31. var camp=db.getObject("donate_page",list.value);
  32. print(camp.Reference_Name);
  33. } else if(list.name == 'tell_a_friend_KEY') {
  34. var camp=db.getObject("tell_a_friend",list.value);
  35. print(camp.Reference_Name);
  36. } else {
  37. print(theTitle);
  38. }
  39. }
  40.  
  41. }
  42. }
  43. ?>
  44. <html xmlns="http://www.w3.org/1999/xhtml">
  45. <head>
  46. <title>1Sky | <?=getTitle()?></title>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.