Jun 14, 2010

CMS image URL

Considering a web content management system, if item content includes images, we can save IMG tags (like other HTML tags) in database. When the system grows up, internal images may be moved to another location, the hardcoded image URLs are then broken. The method used by Nucleus CMS is a solution. It stores item images in a custom format
<%image(pic.jpg|640|480|text to be displayed)%>
where 4 variables, from left to right, are image's file name, width, height, description, respectively. Note that no image path is stored here.

When this custom image expression is fetched from database, first split it into 4 variables, then rebuild a IMG tag with a pre-defined image base URL, e.g., http://www.example.com/image/
<img src="http://www.example.com/image/pic.jpg width="640" height="480" 
 title="text to be displayed" alt="text to be displayed" />

No comments:

Post a Comment