Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2010-01-16 18:36:58
- paagocom
- New Member
- Registered: 2010-01-16
- Posts: 3
if-then-else logic in TextPattern
Hello all,
I am new to TextPattern and just read the book by Potts, Sable and Smith.
Currently I am working on a project involving the mlp and zem_event plugins. It seems that there are some logic shortcomings in the zem_event plugin that make it incompatible with mlp.
An a workaround, I am trying to determine if there is a way to write some php code in a page where I can set the value of a php variable to the value of a txp tag. This way, I can perform some more complex logic evaluations.
<txp:php
global $foo;
$foo = ‘<txp:l10n_get_lang />’;
if ($foo == ‘en’) {
do something
}
</txp:php>
is there anyway to evaluate a txp tag inside some php code?
Many thanks,
Mark
Offline
#2 2010-01-16 18:48:54
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: if-then-else logic in TextPattern
All Txp tags are PHP functions. So of the above you have the following function available to you: l10n_get_lang()
.
Offline
#3 2010-01-16 20:16:32
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: if-then-else logic in TextPattern
There even is <txp:l10n_if_lang>...<txp:else />...</txp:l10n_if_lang>
:)
Offline
#4 2010-01-16 20:16:52
- paagocom
- New Member
- Registered: 2010-01-16
- Posts: 3
Re: if-then-else logic in TextPattern
Thanks for the quick reply.
The snipit I suggested would yield $foo set to a string. How would you force the txp tag/function to be evaluated from within your php code?
Offline
#5 2010-01-16 20:26:29
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: if-then-else logic in TextPattern
I can’t help you with the php code, but depending on what you ‘do something’ is it may well be possible to achieve it with tags only. Or you can wait for Mary ;)
Offline
#6 2010-01-17 17:04:51
- paagocom
- New Member
- Registered: 2010-01-16
- Posts: 3
Re: if-then-else logic in TextPattern
Thanks everyone for the posts and help.
In the end, I found some work arounds using the txp:variable and txp:if_variable tags that allowed me enough conditional logic control to do what was required. It was not required to break out into raw PHP.
The first workaround was used to output the correct static language strings in a txp page/form.
<txp:variable name=“lang” value=’<txp:l10n_get_lang />’ />
<txp:if_variable name=“lang” value=“nl”>
Text in het nederlands
<txp:else />
Text in English
</txp:if_variable>
The second workaround was used to deal with a shortcoming of MLS where I had to filter out articles not in the current language. To do this, one simply has to look for articles with a null “” permlinks.
<txp:variable name=“url” value=’<txp:zem_event_permlink />’ />
<txp:if_variable name=“url” value=”“>
<!— do nothing —>
<txp:else />
<txp:zem_event_date format=”%d %b” class=”“ wraptag=”“ /> –
<txp:zem_event_permlink>
<txp:zem_event_name wraptag=”“ />
</txp:zem_event_permlink>
</txp:if_variable>
I hope this helps someone else down the line.
:)
Offline
#7 2010-01-17 17:21:39
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: if-then-else logic in TextPattern
paagocom wrote:
The first workaround was used to output the correct static language strings in a txp page/form.
That’s what snippets are for: just add ##snippet_name##
in your page/form, and then find the snippet in MLP > snippets, and add the translations.
Offline
Pages: 1