Reference a folder

matthew.wren's Avatar

matthew.wren

08 Jan, 2016 07:36 PM

We're trying to relocate a folder to the root directory from another nested location. Moving it isn't a problem but we have several absolute links to its current location outside of our website and I'm wondering if there's a way so that when a user goes to this location it'll actually lead to the content of the new folder location.

My first thought was to use a reference but I'm not sure I'm doing it correctly or providing the desired results. There's a way to do this by setting up redirect links on the server but that's not something I can do and I want to see if there's a solution within Cascade.

  1. 1 Posted by Ryan Griffith on 08 Jan, 2016 07:52 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    A redirect is definitely what you will want. As you mentioned, you can do it at the server level, or you can upload a very basic HTML file that has a meta refresh tag in the <head> that points to the new location.

    If you go the route of the HTML file, you should also be able to turn on the Rewrite links in file option (under System) and use the [system-asset]/path/to/path[/system-asset] syntax to generate a link dynamically. Note: it is not possible to link to a folder, so it needs to be a link to a page or file.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by matthew.wren on 08 Jan, 2016 08:15 PM

    matthew.wren's Avatar

    Hey Ryan,

    I think this might be a good solution to this problem. I'm testing all this out in our Dev instance of our site and I'm having some issues that I'm hoping you can spot.

    I created a very simple HTML file that contains the meta refresh tag in it but I think my [system-asset] is screwed up.

    here's the file

    <meta http-equiv="refresh" content="0; url=[system-asset]/equity-diversity/index[/system-asset]">
    

    it ends up displaying this in the URL
    http://wwwdev.scranton.edu/academics/provost/equity-diversity/[system-asset]/equity-diversity/index[/system-asset]

  3. 3 Posted by matthew.wren on 08 Jan, 2016 08:55 PM

    matthew.wren's Avatar

    sorry this is the HTML file (it's not much different honestly)

    <html>
        <head>
            <meta http-equiv="refresh" content="0; url=[system-asset]/equity-diversity/index[/system-asset]">
        </head>
        
        <body>
        
        </body>
    </html>
    
  4. 4 Posted by Ryan Griffith on 11 Jan, 2016 01:09 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    The snippet you provided looks correct to me. When you have a moment, please confirm you have the Rewrite links in file option turned on within the HTML file's System pane and that a page at the path /equity-diversity/index indeed exists.

    Thanks!

  5. 5 Posted by matthew.wren on 11 Jan, 2016 02:05 PM

    matthew.wren's Avatar

    Here's the page's system settings

  6. 6 Posted by Ryan Griffith on 11 Jan, 2016 06:13 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    My apologies for the confusion. What we're looking for here would be the Rewrite links in file option when editing your new, simple HTML file, not the page you are linking to.

    Please let me know if you have any questions.

    Thanks!

  7. 7 Posted by matthew.wren on 11 Jan, 2016 06:51 PM

    matthew.wren's Avatar

    That did the trick!

    I'm trying to create a page with a data definition that uses a page chooser to select the page's path. I created a super simple Template with a region in place of the meta field. I placed the meta field into a velocity script and I'm trying to pull the page's path but I continue to get an error. I think something is wrong my variable initialization or maybe this isn't the way I should do it but can you nudge me in the right direction?

    #set($redirect = $_XPathTool.selectSingleNode($contentRoot, '//system-index-block/calling-page/system-page/system-data-structure/internal/path").value)
    
    <meta http-equiv="refresh" content="0; url=[system-asset]$redirect[/system-asset] "/>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <system-index-block name="current page" type="folder" current-time="1452538239512">
        <calling-page>
            <system-page id="31f24a5286c604b375e59258ae20d74b" current="true">
                <name>index</name>
                <path>/academics/provost/equity-diversity/index</path>
                <site>www.scranton.edu</site>
                <link>site://www.scranton.edu/academics/provost/equity-diversity/index</link>
                <system-data-structure definition-path="Re Directs/redirect">
                    <location>Internal</location>
                    <internal type="page">
                        <content />
                        <path>/equity-diversity/index</path>
                        <dynamic-metadata>
                            <name>seo-title</name>
                        </dynamic-metadata>
                        <dynamic-metadata>
                            <name>nav</name>
                            <value>No</value>
                        </dynamic-metadata>
                        <dynamic-metadata>
                            <name>DepartmentProgram</name>
                            <value>-- choose --</value>
                        </dynamic-metadata>
                        <link>site://www.scranton.edu/equity-diversity/index</link>
                        <site>www.scranton.edu</site>
                        <name>index</name>
                        <display-name>Mission</display-name>
                        <title>Office of Equity and Diversity: The University of Scranton</title>
                        <keywords>northeast, Pennsylvania, diversity, veteran, African, Latin, Hispanic, disability, diverse</keywords>
                    </internal>
                    <external />
                </system-data-structure>
            </system-page>
        </calling-page>
    </system-index-block>
    
  8. 8 Posted by matthew.wren on 11 Jan, 2016 07:35 PM

    matthew.wren's Avatar

    I came up with something that works but is this reliable? Is there a better way to do it this way?

    
    #set($redirect = $_XPathTool.selectSingleNode($contentRoot, "//system-index-block/calling-page/system-page/system-data-structure/internal/path").value)
    #set($ext = ".shtml")
    <meta http-equiv="refresh" content="0; url=$redirect$ext"/>
    
  9. 9 Posted by Ryan Griffith on 11 Jan, 2016 08:14 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    but I continue to get an error. I think something is wrong my variable initialization or maybe this isn't the way I should do it but can you nudge me in the right direction?

    Off-hand, the Velocity looks OK. What is the error you are seeing?

    I came up with something that works but is this reliable? Is there a better way to do it this way?

    If you use the [system-asset] pseudo tag, Cascade will add the extension for you on publish, so you shouldn't have to worry about doing this.

    Also wanted to add you can implement the same Velocity Format using the $currentPage variable and Cascade API, thus eliminating the need to use an Index Block all-together. Something like the following should do the trick:

    #set ($redirectPath = $currentPage.getStructuredDataNode("internal")))
    #if (!$_PropertyTool.isNull($redirectPage.asset))
      <meta http-equip="refresh" content="0; url=[system-asset]${redirectPath.asset.link}[/system-asset]"/>
    #end
    

    Also note that I used link instead of path to properly handle cross-Site links.

    Please let me know if you have any questions.

    Thanks!

  10. 10 Posted by matthew.wren on 11 Jan, 2016 08:27 PM

    matthew.wren's Avatar

    Hey Ryan,

    I'm not sure now since I changed the code. It was syntax or lexiconically error? Something strange.

    I knew there was something the remove the need for an index block but I couldn't remember, thanks!

    This current code doesn't seem to redirect the page, am I missing anything? I took what you wrote and used it as the format.

  11. 11 Posted by Ryan Griffith on 11 Jan, 2016 08:55 PM

    Ryan Griffith's Avatar

    My fault, Matthew, my Format had a minor bug in it. When you have a moment, try changing:

    $redirectPage.asset
    

    To:

    $redirectPath.asset
    

    Let me know if this helps at all.

    Thanks!

  12. 12 Posted by matthew.wren on 11 Jan, 2016 09:00 PM

    matthew.wren's Avatar

    hey Ryan,

    I change it and it still appears to just display a blank page and doesn't redirect the link.

    I viewed the source of the blank page and it looks like it's grabbing the link's path but it's not doing anything with it

    <html>
        <head>
            <meta content="0; url=../../../equity-diversity/links.shtml" http-equip="refresh"/>
        </head>
        <body>
        </body>
    </html>
    
  13. 13 Posted by Ryan Griffith on 11 Jan, 2016 09:12 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    Are you able to provide a URL to the file with the refresh <meta> tag?

    Thanks!

  14. 14 Posted by matthew.wren on 11 Jan, 2016 09:17 PM

    matthew.wren's Avatar

    Currently no because this is all being done on our Test instance of Cascade and anything we publish is only viewable on campus.

  15. 15 Posted by matthew.wren on 11 Jan, 2016 09:29 PM

    matthew.wren's Avatar

    I recreated everything in our prod instance but using different pages

    http://www.scranton.edu/_internal/Redirect/base-asset.shtml

  16. 16 Posted by Ryan Griffith on 12 Jan, 2016 02:01 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    My mistake for providing you with incorrect information in my initial code snippet. The http-equip="refresh" attribute should be http-equiv="refresh". Try this adjustment and let me know how it works out.

    Also, I wanted to note you should not need the Maintain absolute links option checked on your redirect page.

    Please let me know if you have any questions.

    Thanks!

  17. 17 Posted by matthew.wren on 12 Jan, 2016 02:45 PM

    matthew.wren's Avatar

    that's its! Thanks so much for all your help with this!

    Can you help me understand this new code snippet? I want to document how to create these redirects now and I want to better understand the tools used to create the format. can you tell me line by line how this works? Most of it looks new to me.

    #set ($redirectPath = $currentPage.getStructuredDataNode("internal"))
    #if (!$_PropertyTool.isNull($redirectPath.asset))
      <meta http-equiv="refresh" content="0; url=[system-asset]${redirectPath.asset.link}[/system-asset]"/>
    #end
    
  18. 18 Posted by Ryan Griffith on 12 Jan, 2016 04:11 PM

    Ryan Griffith's Avatar

    Thank you for following up, Matthew. I am glad to hear the adjustment did the trick.

    #set ($redirectPath = $currentPage.getStructuredDataNode("internal"))
    

    This line uses a sort of global $currentPage variable that we provide to Velocity Formats. The contents of this variable is the calling page's Cascade API Page object. The getStructuredDataNode method is one of many methods available to the object and it takes in a string parameter which is essentially a path (ie group identifier(s) and the field's identifier) to a field you wish to obtain. Again, we're using the Cascade API, so this will return a StructuredDataNode object.

    For more details on the objects, you can use $_PropertyTool.outputProperties($currentPage) and $_PropertyTool.outputProperties($redirectPath).

    #if (!$_PropertyTool.isNull($redirectPath.asset))
    

    This line is simply checking to see if the asset chooser has an asset selected, which will be a Cascade API object, such as a Page, File, etc..

    <meta http-equiv="refresh" content="0; url=[system-asset]${redirectPath.asset.link}[/system-asset]"/>
    

    The important part of this line would be $redirectPath.asset.link, which is outputting the link property of the chosen asset. Again, this is a Cascade API object so you're outputting properties.

    For more details on the chosen asset, you can use $_PropertyTool.outputProperties($redirectPath.asset).

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  19. Ryan Griffith closed this discussion on 12 Jan, 2016 04:11 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac