Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-04-28 18:19:52

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Plugin developers: doWrap(), doTag()

I’ve improved doWrap() and added a new doTag() function in rev 330, in the hopes of making the use of CSS classes more consistent. Both functions accept a $class parameter, which I’d recommend always setting. Here’s my suggestion on what a typical list-tag function should look like:

<pre><code>

function abc_mylist($atts) { extract(lAtts(array( ‘wraptag’ => ‘ul’, ‘break’ => ‘li’, ‘class’ => &#95;&#95;FUNCTION&#95;&#95;, ),$atts));

[…populate the $list array]

return doWrap($list, $wraptag, $break, $class) }

</code></pre>

The doWrap() function is now a bit smarter; it will accept the $break parameter either as a tag name (e.g. $break=‘br’), or as pre-formatted HTML ('<br />'). If $break is specified by tag name, doWrap() should handle both self-closing and enclosing tags correctly (<br /> vs. <p> ... </p>).

doTag() is used for formatting a single item rather than a list. Suggested use:

<pre><code>

function abc_mytag($atts) { extract(lAtts(array( ‘class’ => &#95;&#95;FUNCTION&#95;&#95;, ),$atts));

[…set $content and $tag..]

return doTag($content, $tag, $class) }

</code></pre>

$tag should be specified by name (e.g. ‘div’). doTag() will use a self-closing tag if $content is empty, or an enclosing tag otherwise.


Alex

Offline

#2 2005-04-28 19:20:14

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: Plugin developers: doWrap(), doTag()

Yes this does indeed make sense , so if I understand that correctly this will allow you to format your formtags in any way you like ?
Sorry if I misunderstood something,my php knoledge is pretty much close to zero !


⌃ ⇧ < ⌃ ⇧ >

Offline

#3 2005-04-28 19:24:30

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Plugin developers: doWrap(), doTag()

Not really, this is just a method plugin developers can use to help make tag class attributes behave consistently.


Alex

Offline

#4 2005-04-28 19:35:53

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: Plugin developers: doWrap(), doTag()

Aha , so it will allow the XHTML output of the plug ins to be styled more consistently.

regards, marios


⌃ ⇧ < ⌃ ⇧ >

Offline

#5 2005-04-29 08:32:56

andreas
Member
Registered: 2004-02-28
Posts: 453
Website

Re: Plugin developers: doWrap(), doTag()

I don’t know enough PHP to understand your post. But here’s an idea:

an often-asked question is to include id or class attributes with the wraptag. Is this now possible with this addition? If not, would it be feasible to include it?

Something like: <txp:category_list wraptag="ul#catlist" break="li"/> could output: <ul id="catlist"> ... and <txp:category_list wraptag="ul.catlist" break="li"/> could become <ul class="catlist">...

Offline

#6 2005-04-29 17:14:19

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Plugin developers: doWrap(), doTag()

Andreas,

The patch makes it easy for plugin developers to support class attributes. I didn’t include IDs (yet) because there are some potential validation issues there.

If plugin developers follow my suggestions above, that will allow syntax like this:

<code><txp:abc_mytag wraptag=“ul” class=“catlist” /></code>

“catlist” will be used as the class for the wraptag. The FUNCTION trick makes it default to the tag name (i.e. abc_mytag) as the class name.


Alex

Offline

#7 2005-05-01 21:04:34

andreas
Member
Registered: 2004-02-28
Posts: 453
Website

Re: Plugin developers: doWrap(), doTag()

Ok, I see. What do you think about including this kind of funtionality for the standard TXP tags?

Offline

Board footer

Powered by FluxBB