Great Ocean Media
website design - editorial & pr services - freelance journalism

adi_wrap – Automatic wrapper

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

Usage

Simply put the adi_wrap tag around the contents you need wrapped up:

<txp:adi_wrap wraptag="HTML tag">
	...contained statements...
</txp:adi_wrap>

and if the “…contained statements…” generate some output then they’ll be surrounded by the HTML tag of your choice.

Using adi_wrap will help avoid the creation of empty tags in your markup.

And if you need some extra HTML attributes, it’ll do that too. Have a look in the examples.

Attributes

wraptag="tag"

- the (X)HTML tag (without ‘<>’ brackets) to wrap around the link. Default = “div”.
If there is no content to output then no wraptag is generated.

class="class name"

- the CSS class to be used on the wraptag. Default = “” (none).

html_id="id name"

- the HTML ID to be used on the wraptag. Default = “” (none).

label="text"

- some text to precede the wrapped content. Default = “” (no label).

labeltag="tag"

- the (X)HTML tag (without ‘<>’ brackets) to wrap around the label. Default = “” (no tag).

label_class="class name"

- the class to be used on the label’s tag. Default = “menu_label”.

label_id="id name"

- the ID to be used on the label’s tag. Default = “” (none).

prefix="text"

- some text to precede the content inside the wraptag. Default = “” (no prefix).

suffix="text"

- some text to appended to the end of the content inside the wraptag. Default = “” (no suffix).

html_attribute="text"

- an additional HTML attribute to add to the wraptag. Underscores are converted to hyphens. Default = “” (no extra HTML attribute).

trim="boolean"

- set to “1” to trim whitespace off the ends of your wrapped content. Default for wraptag = “0” (no trim). Default for prefix/suffix = “1” (trim).

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”.

You can add additional HTML attributes to the wrap tag. 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.

Additional information

Support and further information can be obtained from the Textpattern support forum. A copy of this help is also available online. More adi_plugins can be found here.

Version 0.2Download (Uncompressed) SupportTXP 4.5, 4.6