Rendering HTML formated Text File in ColdFusion

Discussion in 'Programming' started by abrown72, Sep 11, 2007.

  1. #1
    Hey all,

    I have been thrown into a new job at work, our CF developer is gone and I need to pick up his job and I have hit a stumbling block in what I am sure is an easy fix. But until I learn more as I go this has got me stumped.

    We have several websites, and at the bottom of of our sites we refrence our other sites. So I have been asked to create a centralized text file that has some html code to display an image that is a link.

    How do I render this text file within CF, so far I have this.

    <cffunction name="HRefs">
    <cfhttp url="http://www.sitename.com/hrefs1.txt" method="get" timeout="60">
    <cfreturn #cfhttp.fileContent#>
    </cffunction>
    <cfoutput>#htmlCodeFormat(HRefs)#</cfoutput>


    But all I get at the bottom is this.

    cftypicallayout2ecfm1480391653$funcHREFS@1feb75

    The text file just contains html code like this.

    <a href="http://www.sitename1.com" alt="text1"><img src="_img/sr_tiny.JPG" alt="image alt1" border ="0" /></a>
    <a href="http://www.sitename2.com" alt="text2"><img src="_img/sr_tiny.JPG" alt="image alt2" border ="0" /></a>


    Any help would be great, even if you just point me to an online tutorial to work my way through this would be great.

    Thanks,
     
    abrown72, Sep 11, 2007 IP
  2. nerveman

    nerveman Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I believe it would be easier to use the CFFILE tag with the "read" attribute, see here for a description: cfquickdocs DOT com/#cffilee

    You can then just display the text with CFOUTPUT.
     
    nerveman, Sep 11, 2007 IP
  3. abrown72

    abrown72 Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks nerveman,

    I followed the instructions within the site that you linked, this is the code I am instructed to use.

    <cffile action = "read" file = "http://www.somesite.com/hrefs1.txt" variable = "HRefs">
    <cfoutput>#HRefs#</cfoutput>


    However this is the error that follows.

    Security: The requested template has been denied access to cffile.
    The following is the internal exception message: access denied (coldfusion.tagext.GenericTagPermission cffile)

    Now I realize what that is telling me, but I am not sure how to fix it.
     
    abrown72, Sep 11, 2007 IP
  4. abrown72

    abrown72 Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I can access the file by just entering it into my browser and it renders the text as html fine, so I am a little lost as to why the CF page is telling me there is a security problem.
     
    abrown72, Sep 11, 2007 IP
  5. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Jamie18, Sep 11, 2007 IP
  6. abrown72

    abrown72 Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    No didn't correct my problem, just introduced another one.
     
    abrown72, Sep 11, 2007 IP
  7. abrown72

    abrown72 Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Here is the fix to my issue, incase anyone else ever needs it.

    <cfhttp url="http://www.somesite.com/hrefs1.txt" timeout="10">
    <cfif IsDefined("CFHTTP.FileContent")>
    <cfoutput>#CFHTTP.FileContent#</cfoutput>
    </cfif>
     
    abrown72, Sep 12, 2007 IP
  8. nerveman

    nerveman Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Sorry, was away. Glad you got it sorted.
     
    nerveman, Sep 16, 2007 IP