Change Typo3 template depending on column content

Diesen Artikel auf deutsch 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.

Share this page:
  • Twitter
  • Technorati
  • del.icio.us
  • StumbleUpon
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • Facebook
  • Fark
  • Digg
  • NewsVine
  • MySpace
  • Slashdot
  • Sphinn

3 Comments

  • Posted by Henny Beyeler on 2010/01/31 at 16:11. Reply

    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

  • Posted by Henny Beyeler on 2010/01/31 at 17:08. Reply

    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

    • Posted by Nicolas on 2010/01/31 at 17:28. Reply

      Great! :-)

      Have a nice day too

Leave a Reply

Your email is never shared. Required fields are marked *

*
*