Search code examples
typo3typoscripttypo3-10.x

How to escape variables in Typoscript setup?


I'm trying to wrap an image with additional HTML elements and parameters, using Typoscript in a Setup Template.

So far, I've managed to wrap elements with HTML, but I'd like to add some parameters as well. The problem occurs, when I try to escape variables in variables - I can't pass UID from one of the parameters.

Below is the sample:

lib.parseFunc_RTE { 
  tags.img = TEXT
  tags.img {
    current = 1    
    preUserFunc = Netresearch\RteCKEditorImage\Controller\ImageRenderingController->renderImageAttributes
    dataWrap = <a href="{parameters:src}" class="lightbox" title="file:{parameters:data-htmlarea-file-uid}:title" data-lightbox-caption="{file:120:title}" data-lightbox-width="{parameters:width}" data-lightbox-height="{parameters:height}" rel="lightbox-group"> | </a>
}

}

The problematic part is here: title="file:{parameters:data-htmlarea-file-uid}:title"

I've tried using {file:{parameters:data-htmlarea-file-uid}:title}, but it still doesn't work and shows error within rendered element: error within rendered element The only working example is when I hardcode the UID ({file:120:title}), but it should be added dynamically, as there are many images.

How can I escape this "double variables"? Or maybe there is another solution to make it work?

==================================================

Here's the full solution of my problem, thanks to @Jo Hasenau

lib.parseFunc_RTE { 
  tags.img = COA
  tags.img {
    10 = TEXT
    10 {
      dataWrap = file:{parameters:data-htmlarea-file-uid}:title
      wrap3 = <a href="{parameters:src}" class="lightbox" title="{|}" 
      insertData = 1
    }
    20 = TEXT
    20 {
      dataWrap = file:{parameters:data-htmlarea-file-uid}:description
      wrap3 = data-lightbox-caption="{|}" data-lightbox-width="{parameters:width}" data-lightbox-height="{parameters:height}" rel="lightbox-group">
      insertData = 1
    }
    30 = TEXT
    30 {
      current = 1
      preUserFunc = Netresearch\RteCKEditorImage\Controller\ImageRenderingController->renderImageAttributes
      wrap = |</a>
    }
  }
}

Solution

  • You can use dataWrap and/or insertData multiple times either by using the official order of stdWrap functions or by squeezing in another "level" of stdWrap functions with stdWrap.functionName

    In this case it's the order of functions combined with a COA to separate the original wrap into smaller chunks and some additional braces provided by another wrap.

    lib.parseFunc_RTE { 
      tags.img = COA
      tags.img {
        10 = TEXT
        10 {
          preUserFunc = Netresearch\RteCKEditorImage\Controller\ImageRenderingController->renderImageAttributes
          dataWrap = file:{parameters:data-htmlarea-file-uid}:title
          wrap3 = <a href="{parameters:src}" class="lightbox" title="{|}" data-lightbox-caption="{file:120:title}" data-lightbox-width="{parameters:width}" data-lightbox-height="{parameters:height}" rel="lightbox-group">
          insertData=1
        }
        20 = TEXT
        20.current = 1
        20.wrap = |</a>
      }
    }
    

    preUserFunc will be executed first, then the first dataWrap will create the actual variable name, followed by wrap3 to get the necessary curly braces, finalized by insertData to fill in all the other variables together with the generated variable.

    The order in this code is just for better readability, but the actual order of function calls within stdWrap is predefined in the PHP code and follows exactly the order of function descriptions in the official docs: https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Functions/Stdwrap.html