Resolve a parameter in XML content
This is an open discussion with 7 replies, filed under Troubleshooting.
Search
Off the top of my head… one way might be to do it in your XSLT if you really want to keep them relative.
<a href="about" class="relative">Blah</a>
And then something like…
<xsl:template match="a[@class = 'relative']"> <a href="{$root}/{@href}"><xsl:value-of select="." /></a> </xsl:template>
Would that work?
Just to clarify, czheng’s example requires the use of the Ninja Technique The code can be found in the XSLT Utilities section: http://getsymphony.com/downloads/xslt/file/20035/.
Thanks for the push in the right direction. I ended up going with a modified version of @czheng’s solution to save on typing.
<!-- Properly base URLs so they work --> <xsl:template match="@href | @src" mode="html"> <xsl:attribute name="{name()}"> <xsl:choose> <xsl:when test="contains(.,'://') or starts-with(.,'/')"><xsl:value-of select="." /></xsl:when> <xsl:otherwise><xsl:value-of select="concat($root,.)" /></xsl:otherwise> </xsl:choose> </xsl:attribute> </xsl:template>
This automatically looks at all @href
and @src
attributes and determines if they to be rewritten with $root
; just like a ninja should! All of the below hyperlinks will resolve to the same location:
<a href="order/incoming/">Open orders</a> <a href="/~sirlancelot/order/incoming/">Open orders</a> <a href="http://www.example.com/~sirlancelot/order/incoming/">Open orders</a>
It also works when Markdown is enabled. Example:
### URL Tests ### - [relative url][0] - [absolute url][1] - [full url][2] [0]: order/incoming/ [1]: /path/to/symphony/order/incoming/ [2]: http://localhost/path/to/symphony/order/incoming/
Is there a good reason that symphony, and many other CMSes use absolute links? Woudn’t it be more simple (and less bytes) to include a base-link in the header of the master template and have all the links relative from there on?
Why do relative links like
<a href="./about">About</a>
not work?
<a href="/about/">About</a>
A leading forward-slash will resolve to the root, so provided you’re not running your Symphony site in a subfolder, this will work, meaning you don’t need to add $root
.
So the root is detected by symphony as the root of your public folder? In the case you have it installed in a subfolder, it still doesn’t resolve to the root of that subfolder, but to the root of your public folder?
In that case why not declare a global param real-root and add:
<base href="{$real-root}">
in the head, and use
<a href="./about">About</a>
wouldn’t this be more elegant?
Create an account or sign in to comment.
I have a textarea section in Symphony that is can contain HTML. I would like to create hyperlinks to other pages (in Symphony) but I don’t know the URL that the textarea content will be rendered at, so relative URLs will not work.
Is there a way I can use a parameter to get the absolute path to a page? I tried putting this in the content but it didn’t work.
The parameters are not expanded :(