How do I retrieve the URL field value from a contentlet which is used as a page content type?

15 views
Skip to first unread message

Bart Plasmans

unread,
Dec 23, 2021, 10:02:32 AM12/23/21
to dotCMS User Group
Hi, 

how are you doing ?
I ran into an issue trying to read the  "url" field value of a content we use as page content.
The value for the field "url"is set in the dotCMS admin for all pages.

In the content type screen the field properties have been set to : 

 -Name: Url
- Variable:url
- Required 
- User Searchable
- System Indexed
- Show in List

When using the ContentletAPI.find  all fields are filled in the response Contentlet, however the "url" field is always "null". 

Contentlet pageContent = APILocator.getContentletAPI().find(pageId, APILocator.getUserAPI().getSystemUser(), false);

Does anyone know if we do something wrong? 

We found an ugly workaround using the dotCMS viewtool "com.dotcms.rendering.velocity.viewtools.content.ContentTool.find()" method.

This returns only the contentmap for a Contentlet, and there the field "Url" is filled:
ContentMap pageContentMap = contentTool.find(page.getInode()); 

Can anyone assist in why the "Url" field is not filled? 

Thank you!

Will Ezell

unread,
Dec 29, 2021, 1:59:31 PM12/29/21
to dot...@googlegroups.com
Bart:
You need to use the HTMLPageAssetAPI and do something like

HTMLPageAsset asset = APILocator.getHTMLPageAssetAPI().findPage(pageId, APILocator.systemUser(), false);

        


Or if you have the contentlet:

        

HTMLPageAsset asset = APILocator.getHTMLPageAssetAPI().fromContentlet(contentlet);


--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/0b983f6d-8423-4ee6-aef5-88cd3e4c4636n%40googlegroups.com.


--



382 NE 191st St #92150
Miami, Florida 33179-3899
Main: 
305-900-2001 | Direct: 978.294.9429

Reply all
Reply to author
Forward
0 new messages