TYPO3 Plugin's position

224 views Asked by At

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!

2

There are 2 answers

0
Jpsy On BEST ANSWER

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;
}
0
Mateng On

Use section frames:

  • Edit the content element you placed your plugin in.
  • Go to Appearance
  • Choose "Frame 1" at "Indentation and Frames"

In the frontend you will realize that the modified plugin container now has an additional css class that can be used for different layout:

<div class="csc-frame csc-frame-frame1" id="c123">

Read more about it here: Custom Frames for Content Elements in Typo3