Reputation: 455
If you have a folder, change the display to a content item, select a page as the default view and use the method context.absolute_url_path() on the folder object, it is incorrect.
When on the context of the folder and when this method is called:
context.absolute_url_path()
It will return /my-folder/my-default-page-object
The absolute_url_path of the context of the folder should just return /my-folder.
Is there some way to get the real path of a object you are on when a default page is set?
Additional Notes: I've tried to subtract the context.getDefaultPage() from the path, the problem is getDefaultPage on the plone site object (aka the root) keeps returning None which makes no sense since a default page is set. I've confirmed with with plones out-of-the-box Page dexterity object and a custom dexterity object.
I'm running Plone 5.
Upvotes: 3
Views: 604
Reputation: 6048
In the case you're describing, context is the default page object -- not it's containing folder. You want the url path of the "canonical" object, which is the current object unless that object is a default view. In the default view case, it's the containing folder.
To get the url path of the canonical object, use the plone_context_state view:
context_state = getMultiAdapter((context, request), name=u'plone_context_state')
canonical_object = context_state.canonical_object()
canonical_url_path = canonical_object.absolute_url_path()
If you're working in a page template, that would be:
context/@@plone_context_state/canonical_object/absolute_url_path
And, if you're after the URL, not just it's path component, use absolute_url rather than absolute_url_path.
Upvotes: 7