How to display Data Collection item based on Web Page name Print

  • 0

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

{bb_datacollection source="Page Header Photos" filter="Item_Name:{bb_pagename}"}

 

Sample Page Template

<!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>

 

Data Collection Custom Layout

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

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

During rendering the final HTML will output this code.

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

 


Was this answer helpful?

« Back

Powered by WHMCompleteSolution