Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-10-31 22:14:49

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,482
Bitbucket GitHub

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

#2 2010-10-31 22:45:04

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

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

#3 2010-10-31 22:47:23

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

#4 2010-10-31 22:55:05

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,482
Bitbucket GitHub

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

#5 2010-10-31 23:13:58

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

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

#6 2010-10-31 23:24:59

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,482
Bitbucket GitHub

Re: Best place to call <txp:variable />

Cool, that makes sense – thank you, Gocom.

Offline

#7 2010-11-01 18:20:00

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

Board footer

Powered by FluxBB