Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-02-23 22:09:02

simsim
Member
Registered: 2006-05-06
Posts: 70

The $atts variable

Hello,

I’ve been looking through the Textpattern code and I have a question about the $atts variable which is passed as a parameter in many functions. What does this variable do? I can’t see where it’s get manipulated as almost every function I’ve seen , whether in the core code or plugins pass it as is!

Thanks.

Offline

#2 2008-02-23 22:20:44

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

Re: The $atts variable

$atts contains the attributes the user specified for that tag, when using it in a template or form.
For example, if you used a tag like this in your template or form:

<txp:example attribute="value" something="else" />

Then the corresponding example($atts) function would receive the following array $atts:

$atts = array(
  'attribute' => 'value',
  'something' => 'else'
)

Most functions feed both the $atts array and an array containing default values for all attributes to the lAtts() function, which returns the combination of the defaults and the user supplied attribute values (user values override the defaults of course). Using lAtts is very highly recommended when you’re creating a tag handler that accepts attributes, if only for that fact that it warns the user when he/she tries to use an attribute that your tag doesn’t support.

Offline

#3 2008-02-23 23:19:54

simsim
Member
Registered: 2006-05-06
Posts: 70

Re: The $atts variable

Thanks Ruud.

Well, I’m starting to get it, however, the nomenclature is a bit confusing to me. I’m assuming from Sable’s tutorial that lAtts refers to local attributes. If so, then why the user-supplied attributes are passed to it? I was thinking that lAtts() is a function to check if user-defined attribute(s) interfere with TXP’s native attributes and issues a warning when that happens.

Offline

#4 2008-02-24 00:13:02

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: The $atts variable

simsim, check out zem’s series, specifically part 3.

Offline

#5 2008-02-24 08:35:14

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

Re: The $atts variable

Or simply look at the code for the lAtts function to see what it does. Plugin authors should be able to understand that code.

Offline

Board footer

Powered by FluxBB