Dynamic Anchors

65 views
Skip to first unread message

Brent

unread,
Dec 19, 2011, 5:16:41 AM12/19/11
to dotCMS User Group
Hi,

Is there a piece of code which can create anchors to all contentitems
which are displayed on a webpage?

TNX

Chris Falzone

unread,
Dec 19, 2011, 6:36:24 AM12/19/11
to dot...@googlegroups.com
Not specifically .. however in the precode of the container you could loop over the contents and build the Links / Anchors.  Then in the code section of the container just output the anchor.


--
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To post to this group, send email to dot...@googlegroups.com.
To unsubscribe from this group, send email to dotcms+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dotcms?hl=en.


Chris Falzone

unread,
Dec 19, 2011, 7:16:44 AM12/19/11
to dot...@googlegroups.com
So, just as a proof of concept:

In the container's pre-loop code you could do something like:

<fieldset>
    <legend>Page Navigation</legend>
    <ul>
#foreach($conIdent in $CONTENTLETS)
      #set($conObj = $dotcontent.find($conIdent))
      <li><href="#con-${conObj.identifier}">$conObj.title</a></li>
#end
    </ul>
</fieldset>

And then in the Code section, something like:

<div class="page_item" id="page-item-$!{ContentIdentifier}">
  <name="con-$!{ContentIdentifier}"></a>
  <h3>$!{title}</h3>
  $!{body}
</div>

Should do the trick.  Of course if your content might be a little different than just a title and body field.

Brent

unread,
Dec 19, 2011, 10:25:14 AM12/19/11
to dotCMS User Group
Hi Chris,

This does the trick!

TNX!

On 19 dec, 13:16, Chris Falzone <chris.falz...@dotcms.com> wrote:
> So, just as a proof of concept:
>
> In the container's pre-loop code you could do something like:
>
> <fieldset>
>     <legend>Page Navigation</legend>
>     <ul>
> #foreach($conIdent in $CONTENTLETS)
>       #set($conObj = $dotcontent.find($conIdent))
>       <li><a href="#con-${conObj.identifier}">$conObj.title</a></li>
> #end
>     </ul>
> </fieldset>
>
> And then in the Code section, something like:
>
> <div class="page_item" id="page-item-$!{ContentIdentifier}">
>   <a name="con-$!{ContentIdentifier}"></a>
>   <h3>$!{title}</h3>
>   $!{body}
> </div>
>
> Should do the trick.  Of course if your content might be a little different
> than just a title and body field.
>

Reply all
Reply to author
Forward
0 new messages