3

Is there a fluid pendant to the new TS option Feature: #82091 - Allow inline rendering in SVG content object or a workaround? The only solution i see(atm) is to write my own viewhelper or i am missed something?

ntiedt
  • 173
  • 3
  • 18
  • 1
    Have a look into EXT:bootstrap_package. Benjamin has already an InlineSvgViewHelper: https://github.com/benjaminkott/bootstrap_package/blob/master/Classes/ViewHelpers/InlineSvgViewHelper.php – Julian Hofmann Apr 29 '21 at 06:33

1 Answers1

5

You can define a typoscript object in your root template:

lib.inlineSvg = SVG
lib.inlineSvg {
  renderMode = inline
  src.field = src
}

(see SVG cObject). Then in your fluid you can do this:

<f:cObject typoscriptObjectPath="lib.inlineSvg" data="{src: 'path/to/the/file.svg'}" />

Of course this limits you to cases in which you have the actual path to the image. You cannot (directly) reference a FAL object. You can, however, just get the files public url:

<f:cObject typoscriptObjectPath="lib.inlineSvg" data="{src: filereference.publicUrl}" />

or

<f:cObject typoscriptObjectPath="lib.inlineSvg" data="{src: filereference.originalResource.publicUrl}" />

depending on whether you are in Extbase cotext or not (see the documentation). You can also pass all other options the cObject takes in the data argument of the f:cObject ViewHelper (e.g. width).