Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-11-22 14:42:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

smd_wrap: conditionally wrap stuff with tags and labels

Have you ever been in any of the following Textpattern situations:

  • Wanted to use wraptag / label on a tag that didn’t have it.
  • Wished you could only wrap a tag around the content if the entire tag block returned some data.
  • Would love to display some alternative <txp:else /> message if the content didn’t exist.
  • Regularly use plugins such as chh_if_data, adi_wrap, rah_function, pax_grep, upm_textile, smd_each, or rah_repeat.
  • Tried to parse data from a feed or inject stuff into the database only to find its format needed to be altered.

If the answer to one or more of the above is yes, then you may like to open the door to this velociraptor in wolf’s clothing that does all the above (and more) in a compact footprint. Spawned from the idea behind the excellent adi_wrap, this plugin goes a step further and allows you to chain transforms together that alter the contained data. Built-in transforms include:

  • trim / append
  • change case
  • linkify
  • sanitize / escape
  • format date & time
  • strip tags
  • split / combine
  • find / replace
  • process with Textile

And if those aren’t enough you can create your own by telling the plugin to pass your data through any number of Forms. At any time, if the content you want to wrap returns nothing, the plugin does nothing so it’s ideal for wrapping round {replacement} tags for other smd plugins like smd_bio, smd_xml, and smd_query to transform data prior to input / output.

Download the plugin and send any feedback, good or bad, my way. Happy clappy wrappy.

Revision history
————————

All available versions and changes are listed here. Each entry indexes the relevant post(s) in the thread to learn about the features.

  • 22 Nov 2011 | 0.1.0 | Initial release
  • 21 Mar 2012 | 0.2.0 | Works like chh_if_data by default. Use <txp:smd_wrap_all> for v0.10 behaviour ; Add form / <txp:yield /> support ; safer <txp:smd_wrap_info /> tag instead of {smd_wrap_it} ; Add time transform as a convenience (same as date) ; Add raw and encode sanitization transforms (thanks, maniqui) ; Add currency, round and number transforms (thanks, jakob, milosevic)
  • 22 Jan 2020 | 0.3.0 | Register tags ; Add multi-byte support (Thanks, summer) ; Use more intelligent title case transform (Thanks, Kroc Camen) ; Silence has_data warning

Last edited by Bloke (2011-11-24 10:44:42)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2011-11-22 16:36:31

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,734
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

Just in case anyone should have any doubts, this is the bees knees!


TXP Builders – finely-crafted code, design and txp

Offline

#3 2011-11-23 20:34:49

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,310

Re: smd_wrap: conditionally wrap stuff with tags and labels

Oh-oh, off to the sandbox with my new smd mould :)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2011-11-24 04:02:24

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

Still getting my head around this one Stef, but have realized that it’s a game changer, in’it.

Offline

#5 2011-11-24 21:46:29

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

About to test this baby.
Consider setting an smd_warp alias to the main function, could be helpful in case of typos. Unless you have already decided to develop smd_warp, the plugin that will help us all to bend space-time as you do.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#6 2011-11-24 21:51:34

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 595
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

Oh please let smd_warp be a different plugin

Offline

#7 2011-11-24 21:58:31

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: smd_wrap: conditionally wrap stuff with tags and labels

smd_warp is, apparently, already in use on Stef’s site.


Steve

Offline

#8 2011-11-24 23:21:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

Rats, you’ve stumbled upon my secret. smd_warp is indeed regularly used in my life. It sports tags such as <txp:infinite_improbability drive=‘128’ />, which of course takes me out for a spot of lunch at Milliways. And back in time for tea and medals.

Last edited by Bloke (2011-11-24 23:21:47)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2011-11-30 11:58:37

sacripant
Plugin Author
From: Rhône — France
Registered: 2008-06-01
Posts: 479
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

I test this plugin in production. It accelerates the development. Very convenient. thank you Steph

A sorry observation, If I write directly.

<txp:smd_wrap wraptag="div" class="col1 bloc" transform="textile">
h1. Image of the day

<txp:image id="3"/>
_Image caption_
</txp:smd_wrap>

Parsing for <txp:image /> ok

But If I write this content in a custom field :

<txp:smd_wrap wraptag="div" class="col1 bloc" transform="textile">
  <txp:custom_field name="my_custom"/>
</txp:smd_wrap>

No parsing for <txp:image /> or Textpattern tag. sniff’

I thought I found a behavior similar to <txp:body /> which analyzes textile and Textpattern tags.

Last edited by sacripant (2011-11-30 11:59:43)

Offline

#10 2011-11-30 12:03:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

sacripant wrote:

No parsing for <txp:image /> or Textpattern tag. sniff’

Try this:

<txp:custom_field name="my_custom" escape="" />

It’s probably just converting the < and > into entities, thus the parser doesn’t recognise it as a tag.

Last edited by Bloke (2011-11-30 12:04:09)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2011-11-30 19:17:18

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

Incredible. replaces about six plugins I’m using and countless lines of code.

Offline

#12 2011-11-30 19:25:10

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

Care to share some examples? I’ve used smd_wrap in one instance only (under the guidance of Bloke) but I think that says more about my lack of imagination than anything else.

Offline

Board footer

Powered by FluxBB