Search code examples
typo3typo3-tca

TYPO3 Plugin's position


How can I programatically determine plugin's position on page? Assuming that I have two instances of the same plugin on a page, I need to determine their position to display slightly different layout. Is it feasible?

Thanks!


Solution

  • Let your extension store a counter variable in $TSFE.
    Such variables will survive from plugin instance to plugin instance and can be used to count the instances that live in the same page.
    Depending on that counter you can change your extension's output.

    Example

    In your function main do something like this:

    // init counter var in the very first plugin instance
    if(!isset($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_'.$this->extKey.'_pi1.']['myCounter'])){
      $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_'.$this->extKey.'_pi1.']['myCounter'] = 0;
    }
    // increment counter var in each plugin instance 
    // and execute code depending on the count
    switch(++$GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_'.$this->extKey.'_pi1.']['myCounter']){
      case 1:
        ...
        break;
      case 2:
        ...
        break;
      case 3:
        ...
        break;
    }