I have a container x, with a Link item y set as display. How can I access programmatically y if I know x?
I tried: getattr(x, 'default_page', None)
, but it returns None all the time.
By using getattr
you may override plone default behavior regarding how to determinate the default page of an object (item or container).
Content objects in Plone inherit BrowserDefaultMixin
, which provides the functionality of getting the default page of a object
The mixin, respectively a utility used by the mixin provides the desired method called getDefaultPage
>>> x = b.getObject()
>>> x.getDefaultPage()
...
This will return the right content object
or view
depending on the configuration on the object, on the FTI and on the View itself and more.
Have a look at get_default_page
for more details.
And even better... This canonical way of getting the default page, would also have helped finding the issue in your case pretty fast, since the method does certain checks to make sure the passed object provides the right "features". A string would not pass those checks.