blog.Resource

Archive:

News-Feeds:


RSS 2.0
RSS 0.91
RDF
ATOM 0.3
February 20, 2008

Conditional content elements

Category: Søren Andersen, TYPO3

By: Søren Andersen

Sometimes you would like to have two content-elemens on the same page, but only one of them showing at the time. When you want to show one of them when a user is logged in, it's no problem, but at other times it's not possible. I would like to discuss a way to solve that problem.

Yesterday I posted a solution to how you can get content-elements to appear inside the text in a RTE. This was something I need on my hypnosis and hypnotherapy faq page. This time, I have found another thing I would like to do with content elements, it regards the same page. Look at the link to "can hypnosis be dangerous?": http://all-hypnosis-links.com/hypnosis-faq/answer/to-question/can-hypnosis-be-dangerous.html

The path includes /answer/to-question/ and then the title of the question. But it's a rather long path and that is not good with the search engines. But I have to use this setup because of realurl and the efaq extension. The optimal solution for me would be that the "answers" part of the extension could be hidden when the user is on /hypnosis-faq.html, and the "questions" part would be hidden when a question is clicked. Put differently, I wan to have the efaq plugin on the same page in the pagetree two times, but only one of them shown when a GET var is present - namely the efaq[uid].

It would be very very nice if there was a field in tt_content where you could insert a GET var, and when this was present, the content element should not be displayed. I could do this very simply by editing the code of efaq, but this method could be useful in many other situations. So my question to you is, how do I accomplish this? When I think about it, it could be possible with a "dummy extension" that extends tt_content, and some typoscript, but that's maybe more advanced than I'm capable of doing. Any suggestions? 


comments

comment #1
Gravatar: S. Teuber S. Teuber February 21, 2008 11:09
As long as you don't need that as a global feature for a lot of pages, it can be done with TypoScript. Check for the desired GET parameter and adjust the plugin/content element-config accordingly. I sometimes use this to combine "list"-views with other content and then hide that other content when the list switches to single view after an element is clicked.

comment #2
Gravatar: Søren Andersen Søren Andersen February 21, 2008 12:51
S. Teuber:
The easiest way to solve it would be to insert if (intval($_GET['efaq']['uid']) > 0) {

}
in the template of the efaq. This is possible because it's lib/div, but conditional content elements could be used for many purposes, so what I'm looking for is if there exists a hook or something, that decides which content-elements should be shown on a page.

comment #3
Gravatar: B. Gschwantner B. Gschwantner February 21, 2008 15:37
The quick and dirty way with pure TypoScript would be to manipulate styles.content.get with conditional comments (assuming you use css styled content):

- Make an extension template on the page
- insert a condition that checks for the pageid and the efaq uid
- inside that condition set the where clause of the CONTENT object so that you exclude the uid of the content element you don't want

This could be something like that:

[globalVar = TSFE:id = 123]
# exclude the content element for the answers (uid 45)
page.10.subparts.CONTENT.select.andWhere = uid!=45
[globalVar = TSFE:id = 123] && [globalVar = GP:efaq|uid > 0]
# exclude the content element for the questions (uid 67)
page.10.subparts.CONTENT.select.andWhere = uid!=67
[global]

I haven't tested that, but I think it should work - maybe it has to be adjusted a little bit. But I think you get the general idea, although this may not be the most beautiful solution...

comment #4
Gravatar: Daniel Pötzinger Daniel Pötzinger February 23, 2008 00:09
With the help of TemplaVoila you can do it transparent for the editor: Like creating a Box FCE with a field "showrule" then you can evaluate this field with typoscript inside the DS and display the contentelement in this grid or not..

comment #5
Gravatar: Søren Andersen Søren Andersen February 24, 2008 20:15
Daniel, I'm not very fond of TemplateVoila, I prefer the normal page module.

Sorry, comments are closed for this post.