Change Typo3 template depending on column content

Tagged Typo3 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 and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Related posts:

  1. Change template if content exists in Typo3
  2. Typo3 in 15 minutes
  3. Include typo3 content elements on every page

5 Comments

  • Posted by Henny Beyeler on 31. January 2010 at 16:11.

    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 31. January 2010 at 17:08.

    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 Constantin Iliescu on 12. August 2010 at 09:38.

    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 < styles.content.get
    NO.doNotLinkIt = 1
    ACT.doNotLinkIt = 1

    but it won't work.

    Any ideas?
    Thank you.

Leave a Reply

Your email is never shared. Required fields are marked *

*
*