Access Content-let data of Page without parseContainer()

16 views
Skip to first unread message

Ryan O'Dell

unread,
Jul 28, 2023, 1:15:10 PM7/28/23
to dotCMS User Group
I'm looking to write-out the title of the page (head) from a specific content-let provided to the page, it renders with "parseContainer" just fine, but I thought there might be a velocity variable to access the content-let field data without using the parseContainer (directly from the template).

Thank you,
Ryan

Will Ezell

unread,
Jul 28, 2023, 2:35:54 PM7/28/23
to dot...@googlegroups.com
Is it a url mapped contentlet or just a contentlet that has been placed on the page?  If it is a urlmapped content, you can obviously just add $URLMapContent.pagetitle.  If it is content that is part of a container, it becomes a bit trickier and you have to hack around a bit.  The list of content identifiers for each container is stored in the velocity context under a variable that looks like this:

$contentletList{container_identifier}{uuid}

Try code like this on a page and see if that gets you going:

<ul>
   #foreach($vel in $context.getKeys())
      #if($vel.startsWith("contentletList"))
          <li><b>$vel</b></li>
         #set($x =$context.get("$vel"))
         <ul>
         #foreach($id in $x)
            #set($con = $dotcontent.find($id))
            #if($con)
               <li>$con.title</li>
            #end
         #end
         </ul>
      #end
   #end
</ul>






--
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/f607bfc6-5d34-4bbc-aaab-221e7aec4b2en%40googlegroups.com.


--



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

Ryan O'Dell

unread,
Jul 28, 2023, 2:50:37 PM7/28/23
to dot...@googlegroups.com
Thanks Will, it's for the URL mapped content details page, yes 👍

$URLMapContent

I assume that'll give me access to all of the content-let fields.

Thank you,
Ryan


You received this message because you are subscribed to a topic in the Google Groups "dotCMS User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dotcms/q7d1xqLUc4Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/CAPL0VyHGf--1%3DoLBRJz2SH9w%3DzW7XaQQH%2BpcM6v90qHrp%3D9-bw%40mail.gmail.com.

Ryan O'Dell

unread,
Jul 28, 2023, 4:29:46 PM7/28/23
to dotCMS User Group
Tested, you can use  $URLMapContent.[field-name]

I've added a small macro to the theme template.vtl as follows:

## The following macro permits you to pass a wanted item and a default item as a fallback
## example: #getItem($!URLMapContent.displayTitle, $!dotPageContent.friendlyName)
#macro(getItem $item $defaultItem)
#if ($UtilMethods.isSet($item))
$item
#else
$!defaultItem
#end
#end

This allows you to setup the page meta from both the url mapped content fields and the fallback page property fields.

Thanks for that Will.

Ryan
Reply all
Reply to author
Forward
0 new messages