Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Best place to call <txp:variable />
Hi.
I’m using <txp:variable />
for the first time (it’s a big day for me), and I have a question for more knowledgeable users than myself.
Clearly there’s a need to set variables before they’re called, but is there an optimum place for the code to be located? Can it be safely called from outside the HTML context, or does it need to live in a certain area of the page code (<body>
, <head>
, etc).
On a related note, I’m using <txp:if_variable>
as a conditional. If I’ve previously set a variable with no variable, like this:
<txp:variable name="banana" value="" />
am I correct in thinking that <txp:if_variable name="banana" />
called later would do nothing?
Thanks in advance, and apologies is this is a dumb question or my terminology isn’t 100% correct.
Last edited by gaekwad (2010-10-31 22:19:34)
Offline
Re: Best place to call <txp:variable />
If you previously set <txp:variable name="banana" value="" />
calling this variable will have zero output.
You can place your form with predefined variables anywhere you wish – there are no CMS’s restrictions. Or you can work without placing all your variables in some form – but collecting getting alike objects together – good practice.
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Re: Best place to call <txp:variable />
You can safely call it outside HTML context.
<txp:if_variable name="banana" />
is the same as <txp:if_variable name="banana" value="" />
, so given <txp:variable name="banana" value="" />
, the if_construct would match (evaluate to TRUE), because an empty string is equal to an empty string.
Offline
Re: Best place to call <txp:variable />
Thank you, sirs – appreciate your time and input.
Is there a preferred method to unset/remove/delete a variable? I’ve checked txp:variable on Textbook but couldn’t see anything that might do it.
Offline
Re: Best place to call <txp:variable />
ruud wrote:
<txp:if_variable name="banana" />
is the same as<txp:if_variable name="banana" value="" />
Not exactly. If_variable does this differently, unlike other conditional tags. If value
is omitted, if_variable check if the variable is set. On the other hand, if value
is set empty it checks if the variable is empty.
Offline
Re: Best place to call <txp:variable />
Cool, that makes sense – thank you, Gocom.
Offline
Re: Best place to call <txp:variable />
Hmm… that’s indeed un-TXP-ish behaviour.
<txp:variable name="banana" value="" />
<txp:if_variable name="banana">sad monkey</txp:if_variable>
That outputs ‘sad monkey’, which is what I had predicted, although for different reasons (as explained by Gocom).
Offline
Pages: 1