Search code examples
typo3typoscriptmicrodatatx-news

Microdata for news item in breadcrumb navigation


With the following code I build my breadcrumb navigation with the according microdata for a BreadcrumbList:

lib.breadcrumb = COA
lib.breadcrumb {
  wrap = <ol class="list-inline" role="menubar" itemscope itemtype="http://schema.org/BreadcrumbList">|</ol>

  10 = HMENU
  10 {
    special = rootline
    special.range = 0|-1

    1 = TMENU
    1 {
      wrap = |

      NO {
        allWrap = <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">|</li>
        stdWrap.htmlSpecialChars = 1
        linkWrap = |
        doNotLinkIt = 0 |*||*| 1
        ATagBeforeWrap = 1
        ATagTitle.field = nav_title // title
        ATagParams = role="menuitem" itemprop="item"
        stdWrap.wrap = <span itemprop="name">|</span>

        after.cObject = COA
        after.cObject {
          5 = TEXT
          5.dataWrap = <meta itemprop="position" content="{register:count_MENUOBJ}|" />
        }
      }
    }
  }
}

This works perfectliy fine, but I have no idea, how to add the item <meta itemprop="position" content="{register:count_MENUOBJ}|" /> for a newsrecord:

This is how it looks at the moment:

// add news title to breadcrumb if needed
[globalVar = GP:tx_news_pi1|news > 0]
  lib.breadcrumb.10.1.NO.doNotLinkIt = 0

  lib.breadcrumb.20 = COA
  lib.breadcrumb.20 {
    wrap = <li class="article" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">|</li>
    after.cObject = COA
    after.cObject {
      5 = TEXT
      5.dataWrap = <meta itemprop="position" content="{register:count_MENUOBJ}|" />
    }

    10 = RECORDS
    10 {
      dontCheckPid = 1
      tables = tx_news_domain_model_news
      source.data = GP:tx_news_pi1|news
      source.intval = 1
      conf.tx_news_domain_model_news = TEXT
      conf.tx_news_domain_model_news.field = title
      conf.tx_news_domain_model_news.htmlSpecialChars = 1
      wrap = <span itemprop="name">|</span>
    }
  }
[end]

Obviously the {register:count_MENUOBJ} is not available for the news item.

How can I get the last value of {register:count_MENUOBJ} from the menu object and increase it by one for the news item?


Solution

  • I had the same problem, my solution is to work with the CUR element:

    lib.breadcrumb = COA
    lib.breadcrumb {
      stdWrap.wrap = <ol class="list list--inline" itemscope itemtype="http://schema.org/BreadcrumbList">|</ol>
      10 = HMENU
      10{
        special = rootline
        special.range = 0|-1
        includeNotInMenu = 1
    
        1 = TMENU
        1{
          noBlur = 1
          expAll = 1
       NO = 1
          NO.wrapItemAndSub = <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">|</li>
          NO.stdWrap.htmlSpecialChars = 1
          NO.stdWrap.htmlSpecialChars.preserveEntities = 1
          #NO.doNotLinkIt = |*| 0 |*| 1
       NO {
        ATagParams = itemprop="item"
        stdWrap.wrap = <span itemprop="name">|</span>
        after = <meta itemprop="position" content="{register:count_MENUOBJ}" />
        after.insertData = 1
       }
    
        }
      }
    }
    
    [(request.getQueryParams()['tx_news_pi1'])['news'] > 0]
     lib.breadcrumb {
      10 {
       1 {
        CUR < .NO
        CUR {
         doNotLinkIt = 1
         stdWrap2 {
            typolink {
               # Detail page
               ATagParams = itemprop="item"
               parameter.field = uid
               additionalParams.data = GP:tx_news_pi1|news
               # If there is a plugin with mode "Detail", the controller and action parameter might be skipped
               additionalParams.wrap = &tx_news_pi1[controller]=News&tx_news_pi1[action]=detail&tx_news_pi1[news]=|
               useCacheHash = 1
               stdWrap = <span itemprop="name">|</span>
            }
          }
         stdWrap.cObject = RECORDS
         stdWrap.cObject {
          if.isTrue.data = GP:tx_news_pi1|news
          dontCheckPid = 1
          tables = tx_news_domain_model_news
          source.data = GP:tx_news_pi1|news
          source.intval = 1
          conf.tx_news_domain_model_news = TEXT
          conf.tx_news_domain_model_news {
           field = title
          }
         }
        }
       }
      }
     }
    [global]