Custom automatically-generated virtual URLs via a permalink attribute
eZ Publish automatically generates nice URLs (called "virtual URLs") for each content node. You can also create custom node URL aliases. However, the main virtual URL is always generated from your object's name or title. Thus it is sometimes too long and affects all internal links. A new feature in 3.10 onwards enables you to create a specific attribute used for the automatically-generated virtual URL. In essence, it enables you to create your own permalink for the object, separate from the object's name or title.
Consider this blog post. By default, its main, automatically-generated virtual URL would be "custom_automatically-generated_virtual_URLs_via_a_permalink _attribute", taken from the object name pattern in the Blog post class definition. While this might be good for search engines, it is a bit long and not very memorable. While we could assign it a custom node URL alias like "custom_permalinks", eZ Publish would still use the long URL for the automatically generated links in places such as the blog's pages.
The solution is the additional URL alias name pattern in the class definition. For versions prior to 3.10, you can either use Kristof's patch (which only affects a few lines in 4 files) or simply upgrade. If the URL alias name pattern is empty, eZ Publish will generate the URLs from the object name pattern as usual. Otherwise, it will use the attribute specified in the URL alias name pattern.
Once your installation is ready, the procedure for assigning a permalink attribute basically consists of two steps. (Note that we're using the term "permalink" a bit loosely here since it actually applies to the entire URL, but we are controlling only the part of the URL specific to the node.)
-
Edit the class definition for the desired class(es). For this site, we are only adding this functionality to the Blog post class so far. In the Administration Interface, click the Setup tab, then the Classes link in the left menu, then the Content link, then finally the Edit button for the Blog post class.
Then, we create a text line attribute, and give it an identifier like "permalink".
-
Configure the URL alias name pattern to be something like "<permalink|title>". This means that eZ Publish will look in the "permalink" attribute to generate the URL, and if this attribute is empty, it will look in the "title" attribute. If you made the "permalink" attribute a required attribute, you can leave out the "title" specification here. See the documentation for full details on the syntax for this field.
For this blog post, I entered "custom permalinks" in the "permalink" attribute, thus the automatically generated URL is http://www.ezsystems.ca/blog/custom_permalinks. Descriptive but succinct!
Comments