Absolute Links not working within a sub-site folder
We've created two sites... One is a top level domain, and one is a subfolder
Example: www.example.com/news/
We have a format located on the top level site and is being used by both sites. It works on the top level site, but the error pages being used on the sub-site are not maintaining absolute links. Is there a way to print out the full URL of the sub-site?
Sample of format code:
#macro(displayLeftNavMainNavigation $xNavAsset)
#set ($xMainNav = $xNavAsset.getStructuredDataNode("main-nav-group"))
#set ($sGroupTitle = $xMainNav.getChild("group-title").textValue)
#set ($sGroupSubTitle = $xMainNav.getChild("group-subtitle").textValue)
#set ($xMainNavLinks = $xMainNav.getChild("nav-items").getChildren())
<nav id="left-main-nav">
<h4 class="stagsansbold subnav-header">$sGroupTitle</h4>
<ul class="news-cat">
#if(!$_PropertyTool.isNull($xMainNav.getChild("internal-link").asset))
#set ($sInternalLink = $xMainNav.getChild("internal-link").asset.link)
#else
#set ($sInternalLink = "")
##set ($sInternalLink = "site://$currentPageSiteName/index")
#end
#set ($sLinkText = $_EscapeTool.xml($xMainNav.getChild("link-text").textValue))
#if (!$_PropertyTool.isNull($xMainNav.getChild("external-link").textValue))
#set ($sExternalLink = $_EscapeTool.xml($xMainNav.getChild("external-link").textValue))
#else
#set ($sExternalLink = "")
#end
<li class="nav-title">
#if ($sExternalLink == "")
#if($sInternalLink != "")
## Use internal link
<a href="$sInternalLink">$sGroupSubTitle</a>
#else
$sGroupSubTitle
#end
#else
## Use external link
<a href="$sExternalLink">$sGroupSubTitle</a>
#end
</li>
## <li class="nav-title"><a href="site://$currentPageSiteName/index" style="color: #ffffff;">$sGroupSubTitle</a></li>
## Get the list of Group links for News Side Navigation
#foreach ($xLink in $xMainNavLinks)
#if(!$_PropertyTool.isNull($xLink.getChild("internal-link").asset))
#set ($sInternalLink = $xLink.getChild("internal-link").asset.link)
#else
#set ($sInternalLink = "")
#end
#set ($sLinkText = $_EscapeTool.xml($xLink.getChild("link-text").textValue))
#if (!$_PropertyTool.isNull($xLink.getChild("external-link").textValue))
#set ($sExternalLink = $_EscapeTool.xml($xLink.getChild("external-link").textValue))
#else
#set ($sExternalLink = "")
#end
#if (!$_PropertyTool.isNull($xLink.getChild("bullet-color").textValue))
#set ($sBulletColor = $_EscapeTool.xml($xLink.getChild("bullet-color").textValue))
#else
#set ($sBulletColor = "#[[#]]#FFF")
#end
<li>
#if ($sExternalLink == "")
## Use internal link
<a href="$sInternalLink"><span style="border-color:$sBulletColor;">$sLinkText</span></a>
#else
## Use external link
<a href="$sExternalLink"><span style="border-color:$sBulletColor;">$sLinkText</span></a>
#end
</li>
#end
</ul>
</nav>
<hr class="hr-leftnav"/>
#end
We've been generally been having a problem linking because the site is in a subfolder.
Thank you for your help.
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
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
1 Posted by Ryan Griffith on 20 Jul, 2016 02:58 PM
Hi Brandon,
Just to confirm, we're dealing with two separate Sites, or a folder within a single Site? If these are two Sites, as long as you use the asset's
link
property, the link that is generated should in a cross-site format (e.g.site://SITE_NAME/path/to/page
). This should tell Cascade to append the Site's URL onto the front of the page's path during publish, so the link should not be relative.Please let me know if you have any questions.
Thanks!
2 Posted by Brandon on 20 Jul, 2016 07:12 PM
Hi Ryan,
It works on the majority of pages, just not on our apache error pages which are located in /_assets/apache-error-pages/
We've even modified the code in the cms.htaccess file:
#
# Site Redirects
#
# Examples:
# Permanent Redirects
# Redirect 301 /test-redirect.html /examples/interior-landing-1/index.html
# Redirect 301 /test-new.html /academics/
#
# Regular Expression Matching Redirects - Redirect a specific page or folder with or without trailing slashes
# RedirectMatch ^/(?i)graduate-programs/accounting/index.html(/|$) "http://www.bus.miami.edu/graduate-programs/specialized-masters/accounting/index.html"
# RedirectMatch ^/(?i)graduate-programs/accounting-accelerated/index.html(/|$) "http://www.bus.miami.edu/graduate-programs/specialized-masters/accounting-accelerated/index.html"
#
ErrorDocument 400 /subsite-1/_assets/apache-error-pages/400.html
ErrorDocument 401 /subsite-1/_assets/apache-error-pages/401.html
ErrorDocument 403 /subsite-1/_assets/apache-error-pages/403.html
ErrorDocument 404 /subsite-1/_assets/apache-error-pages/404.html
ErrorDocument 500 /subsite-1/_assets/apache-error-pages/500.html
3 Posted by Ryan Griffith on 20 Jul, 2016 08:18 PM
Ah, I believe I understand now.
I think recall running into a similar issue when I worked at Millersville University and the solution we used was to add a base tag to the document head that contained the proper URL to use as a starting point for all of the links within the page. Could be worth checking out.
Please let me know if you have any questions.
Thanks!
4 Posted by Brandon on 22 Jul, 2016 07:22 PM
Hello Ryan,
We tried adding the base tag and still no luck. A format was created using the following code:
#set($query = $_.query())
#set($query = $query.byContentType("site://ACAD-COMM-news.miami.edu/News Site Data Types/left-nav"))
#set($query = $query.maxResults(1))
#set($query = $query.siteName($currentPageSiteName))
#set($results = $query.execute())
#if($results.size() > 0)
#set ($xLeftNav = $results[0])
#set ($siteURL = $xLeftNav.getStructuredDataNode("logo-group").getChild("site-url").textValue)
<base href="$siteURL/" />
#end
Then we added a new region on the template of the error pages and made sure that the pages were pointing to the correct areas within the configuration set.
We turned off Absolute Links for the pages and forced the relative links... but it just printed out relative links.. ../../ etc.
Any other suggestions?
Thanks!
5 Posted by Ryan Griffith on 25 Jul, 2016 02:50 PM
Hi Brandon,
Because the links are not cross-Site, you will only be able to get relative or absolute paths, not the full Site URL.
Your best option would be to either hard-code the domain in your base tag or, what some clients do, is name the Site based on the URL and use the Site's name when building URLs.
For example, if your Site's URL is http://www.bus.miami.edu the Site name would be
www.bus.miami.edu
. If you need sub-directories, you would do something likewww.bus.miami.edu+graduate-programs
and perform a string replacement on the+
token.Please let me know if you have any questions.
Thanks!