Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-08-23 07:51:40

draganbabic
Member
From: Novi Sad, Serbia
Registered: 2006-09-27
Posts: 118
Website

Possible through a variable?

I am doing a lot of if_section checks in order to output different content depending on the section the user is on. This is because I am running a bilingual website with a fairly primitive setup that works well enough (one language has sections named in that language, and the other language as well, that’s how we tell them apart.)

This is resulting in my conditionals to look like this:

    <txp:if_section name=",treninzi,vezbe,o-treninzima,saveti,oprema-i-rekviziti,dodaci-ishrani,testovi,galerija-foto,galerija-video,zdrav-zivot,aktuelnosti,health-club,raspored">
    <meta name="description" content="Health Club Novi Sad — Klub za vežbanje, teretana, ishrana, saveti, vežbe, i fitness."/> <!-- this is for serbian site -->
    <txp:else />
    <meta name="description" content="Health Club Novi Sad — Fitness Club &amp; Gym, Diet and Nutrition Information, Advice and Exercise Routines."/>  <!-- this is for english site -->
    </txp:if_section>

Is there a way that I could declare a global variable that would allow me to store all my serbian section in it once, and do an if_serbian → do something, else → do something else?

Repeating a list of sections like this makes things quite error prone.

Thanks.

Offline

#2 2012-08-23 07:59:36

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
Website

Re: Possible through a variable?

Yes, you can use adi_variables and set a global variable (under Content > Variables) called serbian-sections for example, with ,treninzi,vezbe,o-treninzima,saveti,oprema-i-rekviziti,dodaci-ishrani,testovi,galerija-foto,galerija-video,zdrav-zivot,aktuelnosti,health-club,raspored as the value.
Then, in your pages or modules you put (note the single quotes around the txp:variable tag) :

<txp:if_section name='<txp:variable name="serbian-sections" />'>
  ... what to do in the serbian site ...
<txp:else />
  ... what to do in the english site ...
</txp:if_section>

Last edited by CeBe (2012-08-23 08:03:00)

Offline

#3 2012-08-23 08:01:07

draganbabic
Member
From: Novi Sad, Serbia
Registered: 2006-09-27
Posts: 118
Website

Re: Possible through a variable?

I had no idea it could be this easy, I will try it ASAP.

Thanks CeBe!

Offline

#4 2012-08-27 10:46:43

draganbabic
Member
From: Novi Sad, Serbia
Registered: 2006-09-27
Posts: 118
Website

Re: Possible through a variable?

Just following up on this, it worked like a charm. Thanks again CeBe.

Offline

Board footer

Powered by FluxBB