Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-06-23 12:43:02

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,167
Website

adi_wrap - Automatic wrapper

Summary

adi_wrap will wrap its contents in an HTML tag – but only if there’s something to wrap.

See the help supplied with the plugin, or have a look online.

Examples

Typically adi_wrap is of most use when you need something wrapped up in an HTML tag …

… but the contained code doesn’t have its own wraptag attribute, e.g.:

<txp:adi_wrap wraptag="em">
	<txp:custom_field name="might_be_blank" />
</txp:adi_wrap>

… or that the contained statements may not produce any output, e.g.:

<txp:adi_wrap wraptag="p">
	<txp:custom_field name="might_be_blank" />
	<txp:custom_field name="might_be_blank_too" />
</txp:adi_wrap>

… or you want to double wrap something:

<txp:adi_wrap>
	<txp:article wraptag="ul" break="li" keywords="uncommon">
		...contained statements...
	</txp:article>
</txp:adi_wrap>

Note that adi_wrap, in the above example, will use the default wraptag of “div”.

Version History

  • 0.2
    • general purpose attributes, e.g. role=”“, data_thingy=”“
    • ‘prefix’ & ‘suffix’ attributes
    • ‘trim’ attribute (default off for wraptag, on for prefix/suffix)
    • attributes: ‘label’, ‘labeltag’, ‘label_class’, ‘label_id’
    • TXP 4.6 tag registration
  • 0.1
    • initial release

Requirements

Tested in:

  • Textpattern 4.2.0

but is so simple it’s bound to work in all earlier versions too.

Download & Installation

Download adi_wrap and install the plugin in the usual way.

Bugs & Limitations

Let me know if you find any problems.

Feedback

Comments are most welcome.

Last edited by gomedia (2014-07-19 07:43:34)

Offline

#2 2010-06-23 14:22:54

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 344
Website

Re: adi_wrap - Automatic wrapper

Offtopic: may be chh_if_data ?..


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#3 2010-06-23 14:50:19

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,167
Website

Re: adi_wrap - Automatic wrapper

makss wrote:

Offtopic: may be chh_if_data ?..

adi_wrap tackles the same scenario but from a different angle & hopefully makes coding a bit more elegant & strait forward.

I seem to recall that chh_if_data counts whitespace as “data” as well.

Offline

#4 2010-06-23 14:55:06

maniqui
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,068
Website

Re: adi_wrap - Automatic wrapper

As makss already noticed, chh_if_data also provided this kind of functionality, in conditional fashion.
chh_if_data is always in my TXP toolbelt, even when it could be replaced with txp:variable/txp:if_variable and/or txp:smd_if, as it provides a quick shortcut.
But I’ve also noticed some “false positives” when using chh_if_data. Can’t remember right now in which situation, it would output stuff even if every TXP tag inside it returned empty. I’ll have to check.

So, back to adi_wrap, I wonder:

  • does it support (or could it support) txp:else? (no need, imho, to change the plugin syntax to if_adi_wrap. Other plugins like smd_query support txp:else statement if nothing is returned on the first branch)
  • does it ignore HTML? I mean, if contained code is a mix of HTML and TXP tags, and TXP tags returns empty, does it output the contained static HTML? (chh_if_data doesn’t return nothing, if TXP tags returned empty, ignoring HTML stuff).

Adi, being that chh_if_data is currently orphaned, you may want to take a look at its code, and see if there is anything to borrow ;)

Thanks for adding nifty plugins to the TXP ecosystem.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#5 2010-06-23 17:34:15

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: adi_wrap - Automatic wrapper

adi_wrap … hopefully makes coding a bit more elegant & strait forward.

Looks like a clear winner to me. Nice one Adi!

Offline

#6 2010-06-24 13:58:47

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,167
Website

Re: adi_wrap - Automatic wrapper

maniqui wrote:

does it support (or could it support) txp:else?

no & there’s probably not much point if chh_if_data does that job.

does it ignore HTML? I mean, if contained code is a mix of HTML and TXP tags, and TXP tags returns empty, does it output the contained static HTML? (chh_if_data doesn’t return nothing, if TXP tags returned empty, ignoring HTML stuff).

Unlike chh_if_data, adi_wrap takes notice of static HTML within, so really only has a use when the contained code consists of only TXP or plugin tags.

Adi, being that chh_if_data is currently orphaned, you may want to take a look at its code, and see if there is anything to borrow ;)

The idea was for adi_wrap to take a simpler, hopefully more intuitive, and TXP-like approach – to provide a straightforward wraptag functionality for a group of tags.

There’s been some discussion previously about whether something like chh_if_data should be made part of the core, which I think it should, but it was discounted. Maybe now that many TXP tags have been given wraptag attributes, a more stripped-down idea like adi_wrap might be considered?

Offline

#7 2014-07-19 07:43:12

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,167
Website

Re: adi_wrap - Automatic wrapper

Version 0.2 available

  • general purpose attributes, to generate e.g. role=”“, data-thingy=”“
  • ‘prefix’ & ‘suffix’ attributes
  • ‘trim’ attribute (default off for wraptag, on for prefix/suffix)
  • attributes: ‘label’, ‘labeltag’, ‘label_class’, ‘label_id’
  • TXP 4.6 tag registration

General purpose attributes, for example role:

<txp:adi_wrap wraptag="nav" role="navigation">
		...contained statements...
</txp:adi_wrap>

will generate <nav role="navigation"> ... </nav>

<txp:adi_wrap wraptag="li" data_theme="classic">
		...contained statements...
</txp:adi_wrap>

will generate <li data-theme="classic"> ... </li>

Note that you need to specify the attribute using underscores in place of hyphens, these are converted automatically for the markup.

Offline

#8 2014-07-19 07:45:42

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,167
Website

Re: adi_wrap - Automatic wrapper

WRT chh_if_data – I’ve been having another look at it read more here.

Offline

Board footer

Powered by FluxBB