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: 7,755
Website

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.10 | Initial release

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
Moderator
From: Germany
Registered: 2005-01-20
Posts: 2,618
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: 3,937

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
Moderator
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: 581
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
Member
From: UK
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
Textile | My plugins on GitHub | @netcarver

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 7,755
Website

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: 460
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: 7,755
Website

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

Board footer

Powered by FluxBB