Website PortalTutorialDesignersContent Editors

How to display Data Collection item based on Web Page name

With this little bit of code below, you can dynamically display a specific Data Collection Item...

With this little bit of code below, you can dynamically display a specific Data Collection Item using the Web Page's name tag {bb_pagename}.

For example, let's say you wanted to have a custom image at the top of your subpages with having to hardcode the IMG tag on each Web Page. You can place a {bb_datacollection} tag on a Page Template that you assign to your Web pages. Using the 'filter' parameter in your {bb_datacollection} tag to filter only one specific Data Collection item that has a matching name.

Sample tag

<code>{bb_datacollection source="Page Header Photos" filter="Item_Name:{bb_pagename}"}</code>

Sample Page Template

code
<code><!DOCTYPE html>
  <head>
    {bb_siteheader}
    {bb_pageheader}
  </head>
  <body>
    {bb_datacollection source="Page Controller" filter="Item_Name:{bb_pagename}" layout="Page Header"}
    {bb_webpagecontent}
    {bb_sitefooter}
    {bb_pagefooter}
</body>
</code>

Data Collection Custom Layout

This assumes you created a Data Collection 'Image' field called "Page Photo".

code
<code><img src="{{page_photoUrl}}" alt="{{dataNameNoLink}} header photo" />
</code>

During rendering the final HTML will output this code.

code
<code><img src="service-header.jpg" alt="Services header photo" />
</code>

Originally sourced from the BlueberryCMS knowledge base.

Was this article helpful?