Tips and Tricks
Examples and Tutorials
|Use environment parameters in item properties|
A very useful tip for creating dynamic title/breadcrumbs items by using request parameters, session variables or cookie values. This article explains how to use environment parameters in pattern item's value definition. If you don't know what exactly is a "pattern item" you may read explanation of the title/breadcrumbs model in the user manual.
As you may already know, some built-in value types are available for defining the value of a pattern item. In this article we will use the SQL value type. This is a value type that allows you to generate title/breadcrumbs parts (items) based on an SQL query.
Example: SELECT title FROM #__content WHERE id = 5
This query will give you the title of the article with ID 5 (say, "The title"). This item will not be really useful since it always (on every possible page) resolves to "The title". You can easily achieve that with a simple TEXT item without querying the database. The real power of the SQL item type is that you can use environment parameters in the item's properties. Those environment properties include: request parameters, session variables, cookies.
Let's change the query a little:
Changed: SELECT title FROM #__content WHERE id = [request:id]
This by itself is not a valid SQL query since the id field is of a numeric type. But as you might have already guessed the "[request:id]" part will be automatically transformed to the value if the "id" parameter from the current HTTP request. So now, our SQL item will resolve to the title of the currently displayed Joomla article.
This is a very useful feature because it allows great flexibility of the title/breadcrumbs items. It is not limited to the SQL value type. You can use environment parameters in the properties of each value type, no matter built-in or third party.
Note: This given example is meant just to show you how powerful the feature is. The normal way to achieve the result shown in the example is to use the built-in "Current article name" pattern item.