Dominik Mimra
Dominik Mimra

Reputation: 43

Want to change a logo with an if/then condition

I want to select a logo depending on a check box of a page property I have added via extension. The variable selectcompany is shown correctly when dumping the variables.

I am running Typo3 8 LTS.

obj.logo {
  <f:if condition="{field:selectcompany}==1">
    <f:then>
      file = fileadmin/template/private/images/Logo1.png
    </f:then>
    <f:else>
      file = fileadmin/template/private/images/Logo0.png
    </f:else>
  </f:if>    
}

Although the variable is set correctly, always Logo0.png is displayed. When the variable is set to 1, I expected Logo1.png.

Upvotes: 0

Views: 82

Answers (2)

Riccardo De Contardi
Riccardo De Contardi

Reputation: 2148

On TypoScript, it is possible to use a condition (TYPO3 9.5.x syntax):

[page["selectcompany"] == 1]
  obj.logo.file= fileadmin/Images/logo1.png 
[GLOBAL]

Else, you could solve with fluid templating; it should be just:

  <f:if condition="{data.selectcompany}">
    <f:then>
      <f:image src="fileadmin/template/private/images/Logo1.png" alt="" />  
    </f:then>
    <f:else>
      <f:image src="fileadmin/template/private/images/Logo0.png" alt="" />  
    </f:else>
  </f:if> 

I used <f:image> but I guess you could also go with a plain <img> tag, too.

Upvotes: 1

Jo Hasenau
Jo Hasenau

Reputation: 2684

If this is a TypoScript snippet, you can not fill in a Fluid condition there, but have to make use of the TypoScript variant of an if condition.

https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Functions/If.html

Upvotes: 2

Related Questions