SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation ASP Template Help???

    Hi peeps,

    I did create a post which someone replied with a function that would help, but it doesn't seem to be what I need.

    I have created an asp template system. Just for the header etc. What i need to do is be able to change the template easily without creating any links on the page it's self. Basically what I want to do is turn this:

    [link]home|http://www.eycdwebdesign.co.uk/[/link]
    or
    [link]<img src='test.jpg'>|http://www.eycdwebdesign.co.uk/[/link]

    into

    <a href='http://www.eycdwebdesign.co.uk/'>home</a>
    or
    <a href='http://www.eycdwebdesign.co.uk/'><img src='test.jpg'></a>

    This is my template calling script:

    Code:
    	sub pull_template(file)
    	
    		dim grab_template
    		set grab_template = server.createobject("Microsoft.XMLHTTP")
    		if inStr(file, "http://") then
    		
    			grab_template.Open "GET", file, false
    		
    		else
    		
    			grab_template.Open "GET", BaseHREF & file, false
    		
    		end if
    		
    			grab_template.Send
    			
    		template_info = grab_template.responseText
    		
    		if inStr(file, "http://") then
    		
    			template_info = replace(template_info, "images/", file & "/images/")
    			template_info = replace(template_info, "files/", file & "/files/")
    			template_info = replace(template_info, "background-color: #262A32;", "background-color: #FFFFFF;")
    			template_info = replace(template_info, "background-color: #730000;", "background-color: #FFFFFF;")
    		else
    			
    			template_info = replace(template_info, "../../", BaseHREF)
    					
    		end if
    		
    		response.write template_info
    		
    		set grab_template = nothing
    		
    	end sub
    basically i've got the replace function to replace ../../ with my the domain name. ( which makes the script more site more usable through out designs ).

    and I want to do the same, have a general function/sub that will automatically turn [link]home|http://www.eycdwebdesign.co.uk/[/link] which is stored on the template page, into <a href='http://www.eycdwebdesign.co.uk/'>home</a>

    Hope someone can help, its bugging me this.

    TIA

    Gavin

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Run your page through this function, I believe it's what you're after:

    Code:
    <%
    Function ConvertLinks(sPage)
    	Set oRE = New RegExp
    	oRE.IgnoreCase = True
    	oRE.Global = True
    	oRE.Pattern = "\[link\]([^\[]+)\|([^\[]+)\[/link\]"
    	
    	ConvertLinks = oRE.Replace(sPage,"<a href=""$2"">$1</a>")
    
    End Function
    
    sTest = "[link]<img src='test.jpg'>|http://www.eycdwebdesign.co.uk/[/link]" & _
    	"blah blah blah blah<br>blah blah<br>" & _
    	"[link]Google|http://www.google.com[/link]" & _
    	"dum dum da dum" & vbCrLf & _
    	"[link]<img src='../../blah/tst/test2.jpg'>|http://www.eycdwebdesign.co.uk/meh/files/getfile.php?file=something&path=something&thisisalongurl=1[/link]"
    Response.Write ConvertLinks(sTest)
    %>

  3. #3
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation

    Jim,

    You must be the person that replied to my other post. This function works a dream but you have to assign the variable to get it to work.

    Basically: I have generic_template.asp with images, menu's etc. but no asp coding at all.

    Now I have another file with the script I had posted above, which will call generic_template.asp and then use replaces to replace generic information for what I require.

    So when I use <% call grab_template("generic_template.asp") %> it will use xmlhttp to pull the html coding from the generic_template.asp into a new file ( default.asp ).

    I need to set the links on the generic_template.asp so its always updatable. It may come down to having to hand code the links, but I would like to use this script site wide, so I can minimise coding. (html)

    Files attached so you can see exactly what I am doing:

    If you want to test this, you will need to edit subs.inc, there is a line called BaseHREF = "http://localhost/root3/"

    if you are using a testing server or normal, type in the address to the default.asp on this page.

    Just so the scripts know where to look thats all

    Gav
    Attached Files Attached Files

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually, it worked fine because I never called it, tried it on a fresh page and it came back with regular expression errors

    Gav

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it working...

    I put my function in sub.inc
    I call it using
    template_info = ConvertLinks(template_info)
    after the IF that does the replaces

    Worked with both text links and your multi-line image links (which I thought might break it).

    What error are you getting and where?

  6. #6
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heres my new code, for some reason I am getting the following error:

    Code:
    Technical Information (for support personnel)
    
    Error Type:
    Microsoft VBScript runtime (0x800A1399)
    Syntax error in regular expression
    /root3/cgi-bin/inc/sub.inc, line 53
    Could you possibly send your version?

    Cheers

    Code:
    <%
    
    	BaseHREF = "http://localhost/root3/"
    
    	sub welcome_banner()
    	
    		dayname = day(now)
    		monthlyname = monthname(month(now))
    		
    		if dayname = "1" or dayname = "21" or dayname = "31" then
    			
    			dayname = dayname & "<img src='../../images/Template_General/shim.gif' alt='dateprefix' width='2' align='top'><img src='../../images/Template_General/dateprefix-sst.gif' alt='dateprefix' align='top'> "
    		
    		elseif dayname = "2" or dayname = "22" then
    		
    			dayname = dayname & "<img src='../../images/Template_General/shim.gif' alt='dateprefix' width='2' align='top'><img src='../../images/Template_General/dateprefix-nd.gif' alt='dateprefix' align='top'> "
    			
    		elseif dayname = "3" or dayname = "23" then
    		
    			dayname = dayname & "<img src='../../images/Template_General/shim.gif' alt='dateprefix' width='2' align='top'><img src='../../images/Template_General/dateprefix-rd.gif' alt='dateprefix' align='top'> "
    			
    		else
    		
    			dayname = dayname & "<img src='../../images/Template_General/shim.gif' alt='dateprefix' width='2' align='top'><img src='../../images/Template_General/dateprefix-fx.gif' alt='dateprefix' align='top'> "
    			
    		end if
    		
    		if len(monthlyname) > 5 then
    		
    			monthlyname = monthlyname & left(monthlyname, 5)
    			
    		end if		
    		
    		if session("userhash") <> "" then
    		
    			response.write "Welcome User"
    		
    		else
    		
    			response.write(weekdayname(weekday(now)) & " "  & dayname & " " & monthlyname & " " & year(now)) 
    		
    		end if
    		
    	end sub
    	
    	Function ConvertLinks(sPage)
    	
    		Set oRE = New RegExp
    		oRE.IgnoreCase = True
    		oRE.Global = True
    		oRE.Pattern = "\([^\[]+)\|([^\[]+)\[/link\]"
    	
    		ConvertLinks = oRE.Replace(sPage,"<a href=""$2"">$1</a>") ' Causes an error on this line!
    
        End Function
    	
    	sub pull_template(file)
    	
    		dim grab_template
    		set grab_template = server.createobject("Microsoft.XMLHTTP")
    		if inStr(file, "http://") then
    		
    			grab_template.Open "GET", file, false
    		
    		else
    		
    			grab_template.Open "GET", BaseHREF & file, false
    		
    		end if
    		
    			grab_template.Send
    			
    		template_info = grab_template.responseText
    		
    		if inStr(file, "http://") then
    		
    			template_info = ConvertLinks(template_info)
    			template_info = replace(template_info, "images/", file & "/images/")
    			template_info = replace(template_info, "files/", file & "/files/")
    			template_info = replace(template_info, "background-color: #262A32;", "background-color: #FFFFFF;")
    			template_info = replace(template_info, "background-color: #730000;", "background-color: #FFFFFF;")
    		else
    		
    			template_info = ConvertLinks(template_info)
    			template_info = replace(template_info, "../../", BaseHREF)
    			template_info = replace(template_info, "", "")
    					
    		end if
    		
    		response.write template_info
    		
    		set grab_template = nothing
    		
    	end sub
    %>

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is my sub.inc - I think it's pretty much the same.

    One thing to check would be the version of Windows Scripting on the server and if it's not 5.6 upgrade it.

    (having said that, I just noticed that your regexp pattern and mine are different, check that first)
    Code:
    <%
    
    	BaseHREF = "http://localhost/gav/"
    
    	sub welcome_banner()
    	
    		dayname = day(now)
    		monthlyname = monthname(month(now))
    		
    		if dayname = "1" or dayname = "21" or dayname = "31" then
    			
    			dayname = dayname & "<img src='../../images/Template_General/shim.gif' alt='dateprefix' width='2' align='top'><img src='../../images/Template_General/dateprefix-sst.gif' alt='dateprefix' align='top'> "
    		
    		elseif dayname = "2" or dayname = "22" then
    		
    			dayname = dayname & "<img src='../../images/Template_General/shim.gif' alt='dateprefix' width='2' align='top'><img src='../../images/Template_General/dateprefix-nd.gif' alt='dateprefix' align='top'> "
    			
    		elseif dayname = "3" or dayname = "23" then
    		
    			dayname = dayname & "<img src='../../images/Template_General/shim.gif' alt='dateprefix' width='2' align='top'><img src='../../images/Template_General/dateprefix-rd.gif' alt='dateprefix' align='top'> "
    			
    		else
    		
    			dayname = dayname & "<img src='../../images/Template_General/shim.gif' alt='dateprefix' width='2' align='top'><img src='../../images/Template_General/dateprefix-fx.gif' alt='dateprefix' align='top'> "
    			
    		end if
    		
    		if len(monthlyname) > 5 then
    		
    			monthlyname = monthlyname & left(monthlyname, 5)
    			
    		end if		
    		
    		if session("userhash") <> "" then
    		
    			response.write "Welcome User"
    		
    		else
    		
    			response.write(weekdayname(weekday(now)) & " "  & dayname & " " & monthlyname & " " & year(now)) 
    		
    		end if
    		
    	end sub
    	
    	sub pull_template(file)
    	
    		dim grab_template
    		set grab_template = server.createobject("Microsoft.XMLHTTP")
    		if inStr(file, "http://") then
    		
    			grab_template.Open "GET", file, false
    		
    		else
    		
    			grab_template.Open "GET", BaseHREF & file, false
    		
    		end if
    		
    			grab_template.Send
    			
    		template_info = grab_template.responseText
    		
    		if inStr(file, "http://") then
    		
    			template_info = replace(template_info, "images/", file & "/images/")
    			template_info = replace(template_info, "files/", file & "/files/")
    			template_info = replace(template_info, "background-color: #262A32;", "background-color: #FFFFFF;")
    			template_info = replace(template_info, "background-color: #730000;", "background-color: #FFFFFF;")
    		else
    			
    			template_info = replace(template_info, "../../", BaseHREF)
    			template_info = replace(template_info, "", "")
    					
    		end if
    		
    		template_info = ConvertLinks(template_info)
    		
    		response.write template_info
    		
    		set grab_template = nothing
    		
    	end sub
    	
    Function ConvertLinks(sPage)
    	Set oRE = New RegExp
    	oRE.IgnoreCase = True
    	oRE.Global = True
    	oRE.Pattern = "\[link\]([^\[]+)\|([^\[]+)\[/link\]"
    	
    	ConvertLinks = oRE.Replace(sPage,"<a href=""$2"">$1</a>")
    
    End Function	
    %>

  8. #8
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you confirm how you are calling the links, ie [link]blah|blah[/link] or something like that.

    I'm not receiving any errors, which is different from last time, lol had a few problems, copied your modified version, but forgot to change the BaseHREF back to my server settings.

    Just need to know how to run it.

    Cheers

    Gav

  9. #9
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, to test it I had modified templates/generic_header.asp to have some [link]thing|thing[/link] tags in it, is that not how you wanted to use it?

    Code:
    <link href="../css/template_general.asp" rel="stylesheet" type="text/css" />
    <table border="0" cellpadding="0" cellspacing="0" class="bar-top">
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>
    <CENTER>
      <table border="0" cellpadding="0" cellspacing="0" class="main-box">
        <tr> 
          <td class="main-quickmenubg"><CENTER>
              <table border="0" cellpadding="0" cellspacing="0" class="main-quickmenu">
                <tr align="center"> 
                  <td width="85">Wap Access</td>
                  <td width="10">| </td>
                  <td>Control Panel</td>
                </tr>
              </table>
            </CENTER></td>
          <td width="5">&nbsp;</td>
          <td>&nbsp;Home | Products | E-Solutions | Support | Contact Us 
            <% if Session("userhash") <> "" then %>
            || <a href="../engine/?Logout"><strong>Logout</strong></a>
            <% end if %></td>
        </tr>
        <tr> 
          <td>[link]<img src="../../images/Template_General/shim.gif" alt="Generic Image" width="200" height="5"
    	  title="Image Name: Shim.gif
    Size: 1kb
    Location: ../../images/Template_General/" />|http://www.google.com[/link]</td>
          <td>[link]blah|http://www.google.com[/link]<img src="../../images/Template_General/shim.gif" alt="Generic Image" width="5" height="5"
    	  title="Image Name: Shim.gif
    Size: 1kb
    Location: ../../images/Template_General/" /></td>
          <td><img src="../../images/Template_General/shim.gif" alt="Generic Image" width="395" height="5"
    	  title="Image Name: Shim.gif
    Size: 1kb
    Location: ../../images/Template_General/" /></td>
        </tr>
        <tr> 
          <td class="main-logo"><table width="190" height="75" border="0" align="center" cellpadding="0" cellspacing="0" class="main-generic">
              <tr> 
                <td>[link]blah|http://www.google.com[/link]<img src="../../images/Template_General/shim.gif" alt="Generic Image" width="190" height="55"></td>
              </tr>
              <tr>
                <td height="20" align="center"><% call welcome_banner() %>
                </td>
              </tr>
            </table></td>
          <td>&nbsp;</td>
          <td><img src="../../images/Template_General/bluestonewelcome.jpg" width="395" height="75"
    	  title="Image Name: bluestonewelcome.jpg
    Size: 18kb
    Location: ../../images/Template_General/" /></td>
        </tr>
        <tr>
          <td><img src="../../images/Template_General/shim.gif" alt="Generic Image" width="200" height="5"
    	  title="Image Name: Shim.gif
    Size: 1kb
    Location: ../../images/Template_General/" /></td>
          <td><img src="../../images/Template_General/shim.gif" alt="Generic Image" width="5" height="5"
    	  title="Image Name: Shim.gif
    Size: 1kb
    Location: ../../images/Template_General/" /></td>
          <td><img src="../../images/Template_General/shim.gif" alt="Generic Image" width="395" height="5"
    	  title="Image Name: Shim.gif
    Size: 1kb
    Location: ../../images/Template_General/" /></td>
        </tr>
    	<tr><td>[link]blah|http://www.google.com[/link]
    
    blah
    	</td></tr>
      </table>
    </CENTER>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •