Change Typo3 template depending on column content

Let's assume you don't just want to inject some HTML if there is content in a column, but you want to use a completely different layout. This isn't hard to accomplish, see the example:

tmp.templateFile = COA
tmp.templateFile {
	10 = COA
	10 {
		if.isFalse.numRows < styles.content.getRight
		10 = FILE
		10 {
			file = fileadmin/template/1col.html
		}
	}
	20 = COA
	20 {
		if.isTrue.numRows < styles.content.getRight
		10 = FILE
		10 {
			file = fileadmin/template/2col.html
		}
	}
}

The ifs check if there is or isn't content in the right column and the COA returns the correct cObject, FILE in this case.And then in your main typoscript something like:

page.10.template < tmp.templateFile

instead of the more usual

page {
	10 = TEMPLATE
	10 {
		template = FILE
		template {
			file = fileadmin/template/1col.html
		}
	}
}

That's all.

6 comments

  1. avatar
    wrote this comment on

    Hi Nicolas

    Thanks for putting the 'Change Typo3 template depending on column content' on your website. Very easy and understandable. But somehow it does not seem to work. The 'IF' construct does not work, afterthat I have no layout at all. How can I check why?

    Thanks in advance
    Kind Regards
    Henny

  2. avatar
    wrote this comment on

    Hi Nicolas

    I found the reason myself. It is working fine now. Thank you very much. Before I found your entry I had a long search on the internet.

    Have a nice day
    Henny Beyeler

  3. avatar
    wrote this comment on

    Great! :-)

    Have a nice day too

  4. avatar
    wrote this comment on

    Hi, Nicolas!

    Does the condition in your example work in a TMENU?
    I'm trying to use the condition to un-link menu items which point to pages without content.

    I tried:

    if.isFalse.numRows &lt; styles.content.get
    NO.doNotLinkIt = 1
    ACT.doNotLinkIt = 1

    but it won&#039;t work.

    Any ideas?
    Thank you.

  5. avatar
    wrote this comment on

    Not really, haven't worked with typoscript too much lately.

  6. avatar
    wrote this comment on
    Great article! What if, instead of checking for content in another column, you want to check for content in another page? The thinking is, if a page does have content in a specific column, then we load a different template - kind of an override feature. Thanks, -Scott.

Reply

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityPianoFontGnuPGThunderbirdJenkinshome-assistant-logo