Absolute links within a site

thugsb's Avatar

thugsb

09 Sep, 2014 03:10 PM

Is there a way to create absolute links within a site, without using the "Maintain Absolute Links" checkbox?

I'm trying to output opengraph image tags. For a page within the www-admission site, when I use <meta content="{link}" property="og:image"/> it outputs <meta content="site://www-admission/media/images/image.jpg" property="og:image"/> and using {path} makes it <meta content="/media/images/image.jpg" property="og:image"/>, neither of which work.

I need it to output <meta content="http://www.site.com/admission/media/images/image.jpg" property="og:image"/>. But I don't want to use the 'Maintain Absolute Links' option, since I don't want the rest of the links on the page to be absolute.

Happy to use <xsl:processing-instruction name="php"> if that would help, but I can't figure out a way (some of our sites publish a single folder deep, e.g. /admission/, but some are several levels deep, e.g. /news-events/news/).

  1. 1 Posted by thugsb on 09 Sep, 2014 06:24 PM

    thugsb's Avatar

    It seems to me that this has been an active discussion for about 4 years now. I'm amazed that there hasn't been a <url> added to system-page's and file chooser path's by now, which would draw on the page's site's URL. It's obviously something that people have been desiring for years. Is it possible yet?

  2. 2 Posted by Ryan Griffith on 09 Sep, 2014 07:59 PM

    Ryan Griffith's Avatar

    Hi,

    This suggestion would definitely be useful and is something we have been keeping our eye on, but have not yet scheduled. If you have not already, please vote up the following related suggestions where applicable:

    In the meantime, I had an idea if you are willing to try it out. You could add a CUSTOM META region to the template and apply a Velocity Format that is within a different Site (perhaps a shared Site somewhere). This Velocity Format would use the Locator Tool to obtain the calling page information and structured data, including your image. Using the link path to this image should generate a cross-Site link to the file, which should in-turn tell Cascade to append the Site URL onto the front of the generated link.

    Please let me know if you have any questions.

    Thanks!

  3. 3 Posted by thugsb on 09 Sep, 2014 09:37 PM

    thugsb's Avatar

    That sounds like a great idea, and I'm willing to give it a try. But I've not really used velocity before. Can you lead me through this step-by-step please? Tx!

  4. 4 Posted by Ryan Griffith on 10 Sep, 2014 12:15 PM

    Ryan Griffith's Avatar

    Sure, not a problem at all. When you have a moment, please attach the XSLT Format you are currently using to generate the <meta> tags and I will try to port it over to Velocity to get you started.

    Please let me know if you have any questions.

    Thanks!

  5. 5 Posted by thugsb on 11 Sep, 2014 06:37 PM

    thugsb's Avatar

    This acts on a 'Current Page' index block.

  6. 6 Posted by thugsb on 16 Sep, 2014 05:57 PM

    thugsb's Avatar

    Bump

  7. 7 Posted by Ryan Griffith on 16 Sep, 2014 07:46 PM

    Ryan Griffith's Avatar

    My apologies for the delayed response, got caught up with the conference the past few days.

    While I work on the Velocity Format, what version of Cascade Server are you currently running? If you are on version 7.10.1, there is a pre-defined variable that we provide to access information/properties for the calling page. This would bypass the need to use the Locator Tool, simplifying the Format a bit more.

    Thanks!

  8. 8 Posted by thugsb on 16 Sep, 2014 08:04 PM

    thugsb's Avatar

    v7.12.1

  9. 9 Posted by Ryan Griffith on 16 Sep, 2014 08:15 PM

    Ryan Griffith's Avatar

    Perfect, thank you.

    Looking over your XSLT, I'm thinking this variable (nor the Locator Tool) will work out because you need to use XPath to grab <iframe> and <img> src attributes at any level. In that case, you would need to continue using your current page Index Block along with the Format.

    Let me take a closer look, I should be able to port this over some time tomorrow.

    Thanks!

  10. 10 Posted by Ryan Griffith on 17 Sep, 2014 01:56 PM

    Ryan Griffith's Avatar

    Hi,

    I believe I was able to port over your XSLT Format, but did not have a chance to test the code. When you have a moment, give the following a try and let me know how it works out:

    #set ($page = $_XPathTool.selectSingleNode($contentRoot, "//calling-page/system-page") )
    #set ($pageSD = $page.getChild("system-data-structure") )
    
    <meta content="${_EscapeTool.xml($page.getChild("title").value)}" property="og:title"/>
    <meta property="og:url" content="[system-asset]${page.getChild("link").value}[/system-asset]" />
    
    #set($output = "#renderMetaOGType()")$output.trim()
    #set($output = "#renderMetaOGImage()")$output.trim()
    
    #macro (renderMetaOGImage)
        #set ($contentImages = $_XPathTool.selectNodes($pageSD, "main_column/content//img") )
        #set ($galleryImage = $_XPathTool.selectSingleNode($pageSD, "gallery/slide/img[path != '/']") )
        #if ($contentImages.size() > 0)
            #foreach ($image in $contentImages)
                <meta content="${image.getAttribute("src").value}" property="og:image"/>
            #end
        #elseif ($galleryImage)
            <meta content="${galleryImage.getChild("link").value}" property="og:image"/>
        #else
            <!--#passthrough<?php include($_SERVER['DOCUMENT_ROOT'] . "/core/Hero/ssi/opengraph.html"); ?>#passthrough-->
        #end
    #end
    
    #macro (renderMetaOGType)
        #set ($youTubeVideos = $_XPathTool.selectNodes($pageSD, "main_column/content//iframe[contains(@src, 'youtube')]") )
        #if ($youTubeVideos.size() > 0)
            <meta content="video.other" property="og:type"/>
            <meta content="${_EscapeTool.xml($youTubeVideos.get(0).getAttribute("src").value}" property="og:video"/>
        #else
            <meta content="article" property="og:type"/>
        #end
    #end
    

    Note: make sure this Format is within another Site so the cross-Site links are written with the Site's URL.

    Please let me know if you have any questions.

    Thanks!

  11. 11 Posted by thugsb on 18 Sep, 2014 01:25 PM

    thugsb's Avatar

    I'm afraid it's still doing the site:// thing. :(

    First off, this line was missing a ")" after .value:

    <meta content="${_EscapeTool.xml($youTubeVideos.get(0).getAttribute("src").value}" property="og:video"/>
    

    Here's the output of a page with images in the main_column:

    <meta content="International Students and SLC" property="og:title"/>
    <meta content="index.html" property="og:url"/>
    <meta content="article" property="og:type"/>
    <meta content="site://www-admission/media/images/shutterstock_89227387.png" property="og:image"/>
    <meta content="site://www-admission/media/images/intl-initiatives-1280.png" property="og:image"/>
    

    And here's the output of a page with gallery images:

    <meta content="Undergraduate Admission" property="og:title"/>
    <meta content="index.html" property="og:url"/>
    <meta content="article" property="og:type"/>
    <meta content="site://www-admission/media/images/admission-home-slides/admission-home-slide-2.jpg" property="og:image"/>
    

    The images are in the same site as the pages, but the format is in a different site. Even if the images are in a different site, the output is still site://....

    Also, of course, the og:url is now invalid, but if we fix the image issue, I bet we can fix the URL in a similar way. :)

    Any ideas? Thanks!

  12. 12 Posted by Ryan Griffith on 18 Sep, 2014 01:35 PM

    Ryan Griffith's Avatar

    Thank you for following up and my apologies for the typo in my sample.

    With those sample outputs, I am assuming those are from within Cascade Server, correct? If so, we want the site:// prefix, because this is what tells Cascade Server the link is cross-Site and to append the Site's URL onto the front during the publish job's link rewriting process.

    That being said, it looks like something is incorrect with the og:url tag because that does not have the cross-Site link within it. Perhaps try removing the [system-asset] pseudo tag and see if that changes the output:

    <meta property="og:url" content="${page.getChild("link").value}" />
    

    Please let me know if you have any questions.

    Thanks!

  13. 13 Posted by thugsb on 18 Sep, 2014 01:40 PM

    thugsb's Avatar

    I'm afraid those outputs are from the published pages:

    http://pending.slc.edu/admission/index.html and http://pending.slc.edu/admission/apply/international/index.html

    Removing the [system-asset] form the URL results in the site:// output on the published pages too.

  14. 14 Posted by Ryan Griffith on 18 Sep, 2014 03:16 PM

    Ryan Griffith's Avatar

    Definitely interesting, so it sounds like we need the [system-asset] tags around all of the links so they are tracked by Cascade and rewritten, but I'm not sure why the Site URL isn't being appended.

    Perhaps I am thinking of XML/XHTML blocks that are cross-Site. One of our developers mentioned that Formats that are in a different Site probably won't do the trick since the context is the page itself and not the format. Perhaps we can try moving the Template to another Site, that might make those links cross-Site.

    Please let me know if you have any questions.

    Thanks!

  15. 15 Posted by thugsb on 18 Sep, 2014 03:37 PM

    thugsb's Avatar

    The template was in a separate site, the same as the format. I moved it into a third site, and the same result.

    Putting [system-asset] around them makes the links relative to the page, meaning that they don't have the folder container or domain. So

    <meta content="media/images/admission-home-slides/admission-home-slide-2.jpg" property="og:image"/>
    
    Where the desired result is (without *'s):
    <meta content="*http://www.slc.edu/admission/*media/images/admission-home-slides/admission-home-slide-2.jpg" property="og:image"/>
    

    Other ideas? :(

  16. 16 Posted by Ryan Griffith on 14 Oct, 2014 12:24 PM

    Ryan Griffith's Avatar

    Hi,

    My apologies for not responding sooner.

    I was checking with our Services team to see if they have helped any clients with similar functionality, but to their knowledge they have always hardcoded the Site URL in cases like this. This is because there is currently no way to obtain the Site URL unless the link to the asset is cross-Site.

    The only solutions I can think of would be to:

    • Hard code the Site URL
    • Perhaps add a "config" Structured Data Block to each Site that defines the Site URL value. Use a shared Velocity Format that obtains the Site's config block using the Locator Tool and the calling page's Site
    • Move the assets that need the URL appended into an entirely separate Site so the links are in-fact cross-Site

    I'm leaning towards the second option since it would be more re-usable and flexible in the long run.

    Please let me know if you have any questions.

    Thanks!

  17. 17 Posted by thugsb on 14 Oct, 2014 03:04 PM

    thugsb's Avatar

    I've managed to fix this by effectively hard-coding the site URL. We've renamed out Sites in cascade to follow this convention: www.slc.edu+folder+subfolder

    That was we can determine the site URL from the site name. Not the best solution, but it works for now.

  18. 18 Posted by Ryan Griffith on 14 Oct, 2014 06:59 PM

    Ryan Griffith's Avatar

    Thank you for following up with your workaround, definitely something to keep in mind as I think I have seen that before. It's a bit less work than my proposed solution of using a structured data block and the Locator Tool.

    Again, my apologies for not being able to provide you with a simple solution. Definitely vote up the suggestions from our Idea Exchange that I listed previously if you have not already.

    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 14 Oct, 2014 06:59 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