-
Improvement
-
Resolution: Fixed
-
Neutral
-
None
-
None
-
-
Yes
-
Empty show more show less
-
Kromeriz 75
-
3
The cmsfn provides:
cmsfn.contentByPath(path, workspace)] cmsfn.nodeByPath(path, workspace)] cmsfn.contentById(id, workspace)] cmsfn.nodeById(id, workspace)]
Two problems (1. & 2.) when the target node does not exists because of:
- path outdated/invalid
- id outdated/invalid
1. Floods the logs with the thrown exceptions of trying to fetch the content.
The templater ha no way to prevent the throwing of the exceptions, even he knows it is absolute valid an item does not exists.
There are methods in jcr session to actually know if it exists before requesting it:
jcrSession.nodeExists("pathToCheck"); jcrSession.itemExists("pathToCheck"); jcrSession.propertyExists("pathToCheck");
There is no jcr method for checking if an id exists -> needs to catch the ItemNotFoundException
2. Too many unnecessary if checks needed:
-It would be nice for the templater to be able to check if a path or an id exists within a workspace, BEFORE trying to fetch the content of it.- ?hasContent in an if statement might be used instead
-I added the needed Methods to info.magnolia.templating.functions.TemplatingFunctions and info.magnolia.jcr.util.SessionUtil as a patch.-
-Here an example of how easy the code becomes, and no unnescessary exception is logged:-
[#-- By Path (will produce logs): From --] [#if eventPath?has_content] [#assign eventNode = cmsfn.contentByPath(eventPath, "events")] [#if !eventNode?has_content] [#-- Reacting on non resolvable path --] [/#if] [/#if] [#-- By Path: To --] [#if cmsfn.contentExists(eventPath, "events")] [#assign eventNode = cmsfn.contentByPath(eventPath, "events")] [#else] [#-- How ever to react on non existing path. But no need to check eventNode?has_content to get into the logical 'else' --] [/#if] [#-- By Id (will produce logs): From --] [#if eventId?has_content] [#assign eventNode = cmsfn.contentById(eventId, "events")] [#if !eventNode?has_content] [#-- Reacting on non resolvable path --] [/#if] [/#if] [#-- By if: To --] [#if cmsfn.idExists(eventId, "events")] [#assign eventNode = cmsfn.contentById(eventId, "events")] [#else] [#-- How ever to react on non existing id. But no need to check eventNode?has_content to get into the logical 'else' --] [/#if]
- supersedes
-
MAGNOLIA-4671 Bad error handling for method for info.magnolia.templating.functions.TemplatingFunctions#link
- Closed
- mentioned in
-
Page Loading...