[opencms-dev] <cms:link> tag - when to use?

Paul-Inge Flakstad flakstad at npolar.no
Tue Nov 11 14:48:39 CET 2014


Hi Chris,

1) About the <cms:link> tag
It's definitely a bad idea to drop the <cms:link> tag. It's vital to properly perform URI conversion/substitution/translation (whichever word you prefer).

<cms:link> makes sure any OpenCms-relative URI is converted to a site-relative URI. This function is *vital* if your site has a prefix like "/opencms/opencms".

E.g.: 
Say you have a stylesheet with an OpenCms-relative URI like "/system/modules/module/resources/style.css". This URI is the one you should always use in your code (or, alternatively, an equivalent like "../resources/style.css"). Now, if your OpenCms site has a prefix - "/opencms/opencms" - then the site-relative URI is "/opencms/opencms/system/modules/module/resources/style.css". Note the difference in the two URIs.

Of course, most real-world sites have no prefix. As a result, the OpenCms-relative URI and the site-relative URI are identical. So, you might be tempted to drop the <cms:link> tag. Don't.

First of all; Things won't work properly if you at some point should *introduce* a prefix like "/opencms/opencms". (You probably won't do that for production sites or anything, but perhaps some of your OpenCms installs used for testing have a prefix? -I know some of mine do. Proper use of the <cms:link> tag is important if you want your stuff to work on those test installs.)

Secondly; The <cms:link> tag handles another important feature: Link substitution for exported resources.

Static resources - stylesheets, javascripts, images etc. - are typically exported by OpenCms over to the server's real file system (RFS), and mostly served from there. (More efficient.) If you drop using the <cms:link> tag, these resources will always be served from OpenCms - never from the RFS. (They will still be exported though. Not that it matters much.)

When you use <cms:link> around a URI that refers to a resource that gets exported, that URI is automagically substituted (in the Online project) with the URI of its corresponding exported resource. 

E.g.: "/img/myimage.jpg" --becomes--> "/opencms/export/sites/mysite/img/myimage.jpg"


2) About your script error
Very little info to work with, so it's a long shot: Please make sure you've declared the "cms" taglib prefix (in the directives at the top of the JSP), like this:
<%@taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>

If that's not it, please provide further info so we may help you identify the error.

Cheers,
Paul

-----Original Message-----
From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Christoph Kukulies
Sent: 11. november 2014 11:01
To: The OpenCms mailing list
Subject: [opencms-dev] <cms:link> tag - when to use?

I'm importing a site from Wordpress into OpenCms and while looking at the links used in the original page I'm asking myself whether I should surround every link, e.g. a page that is invoked behind a menu item, with a "<cms:link>/actual/link/</cms:link>". Is it necessary, what is the benefit?

Side note: when I have the jsp open in the workplace and I'm cut/pasting a such modified code, by CTRL-A selecting all and pasting (CTRL-V) the modified code with all the new links I'm ending in a script error, saying that a script on the page is no longer functioning.


--
Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de _______________________________________________
This mail is sent to you from the opencms-dev mailing list To change your list options, or to unsubscribe from the list, please visit http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev






More information about the opencms-dev mailing list