Question

I've written a brief CFscript to encode/decode links:

    function link_encode(str) {
    x = Replace(str, "&", "and", "ALL");
    y = Replace(x, " ", "_", "ALL");
    z = Replace(y, "/", "|", "ALL");
    return z;
}

function link_decode(str) {
    x = Replace(str, "and", "&", "ALL");
    y = Replace(x, "_", " ", "ALL");
    z = Replace(y, "|", "/", "ALL");
    return z;
}

This is in a file which is include in the site header (included on every page)

<cfinclude template="/includes/cfScriptFunctions.cfm">

This works fine in a 'normal' page:

<cfset link = link_encode(sub_menu.name)>

But, for SEO purposes I rewrite URLs via web.config:

<rule name="categories_1" stopProcessing="true">
<match url="category1/(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/category1.cfm?id={R:1}" />
</rule>

When I land on this page, Coldfusion returns the error : "Variable LINK_DECODE is undefined". But, if I try to include the cfscript file in the page Coldfusion returns the error: "Routines cannot be declared more than once. The routine link_decode has been declared twice in different templates.". This tells me that the routine is available so why isn't it being found ?

update Ooops... My Fault ... I was calling the function before it had been included in the page ... Duh.

Was it helpful?

Solution

Question... on your cfml page... when are you calling the link_decode? When are you including the header file? I've seen people call the link decode above their headers, to get queries built etc, to put data into the header, but the header has the cfscript. Check your flow, incase you're calling it before the include.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top