Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

mrdale
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,202
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: Geneva, Switzerland
Registered: 2004-08-04
Posts: 338
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

#13 2011-12-01 12:23:45

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

Re: smd_wrap: conditionally wrap stuff with tags and labels

Bloke a écrit:

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

⚡☹⚰⚠☢☠☣

Still an attribute that my brain had completely forgotten.
Thanks Steph

Offline

#14 2011-12-02 01:29:27

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

Re: smd_wrap: conditionally wrap stuff with tags and labels

I wonder if converting smd_wrap into smd_warp is just a matter of adding support for form attribute and txp:yield.
In equation:

txp:smd_wrap + form="" + txp:yield = txp:smd_warp 
// an txp:output_form on stereoids.

the Universe trembles in fear


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#15 2011-12-02 01:51:12

TNT
Member
From: Rotterdam, Netherlands
Registered: 2006-01-06
Posts: 248
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

maniqui wrote:

the Universe trembles in fear

I already felt a tremor in the Force…


Prrrrrrrr

Offline

#16 2011-12-02 09:05:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,620
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

maniqui wrote:

adding support for form attribute and txp:yield.

I can’t believe I missed off the form. That’s a two-line addition which I’ve done ready for the next version, thanks. But can you give me a use case for <txp:yield> please? I can’t figure out how the plugin needs to change to enable you to implement it. To trigger yield you need to use <txp:output_form> as a container, which you can wrap already; viz. this contrived example:

<txp:smd_wrap transform="replace||teapot|toaster">
   <txp:output_form form="wrapcontent">I'm a little teapot</txp:output_form>
</txp:smd_wrap>

Where wrapcontent contains:

<div>
<txp:yield />, short and stout
</div>

P.S. The item attribute can also be used to specify content for wrapping, and supports tags-in-tags if you so desire.

Last edited by Bloke (2011-12-02 09:08:16)


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

#17 2011-12-02 17:21:07

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

Re: smd_wrap: conditionally wrap stuff with tags and labels

Bloke wrote:

I can’t believe I missed off the form. That’s a two-line addition which I’ve done ready for the next version, thanks.
But can you give me a use case for <txp:yield> please?

Errrrr… emmmmmm… just put it there, don’t ask! :)
First, the use cases for form attribute:

  • as with most other tags that support form attribute: to call a form, and render it. Nothing fancy (just an alternative to the container use).
  • in tandem with txp:yield.

The example you provided is a good one, and that’s what I would do if I need to use smd_wrap and the power of txp:output_form/txp:yield combo.

What I was thinking was cutting down the code length.
The following example is almost the same as the one you posted, just removed txp:output_form and put the form attribute directly in txp:smd_wrap.

<txp:smd_wrap form="wrapcontent" transform="replace||teapot|toaster">
   I'm a little teapot
</txp:smd_wrap>

(the wrapcontent form remains the same as in your example)

Of course, if this would be implemented, it opens a few questions (and maybe some cans for worms):
Should the wrapped content be processed before/after passing it to the specified form? Maybe that would be controlled by just another attribute.

P.S. The item attribute can also be used to specify content for wrapping, and supports tags-in-tags if you so desire.

I must admit that when I saw this attribute, I wondered, and still wonder, why someone would prefer to use it, instead of just going with the container way of using smd_wrap. Yes, it may shorten the code (removing the closing </txp:smd_wrap>), but then, it becomes probably less legible. Maybe just a matter of preference? Or you devised other use cases?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#18 2011-12-02 17:24:32

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

Re: smd_wrap: conditionally wrap stuff with tags and labels

Moreover, I’d extend txp:yield capabilities to other (any?) txp:tag that admits a form attribute and can be used as container tag. Of course, this should be discussed into a proper feature request, not here at smd_wrap thread.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#19 2011-12-03 07:00:01

des
Member
Registered: 2011-01-05
Posts: 3

Re: smd_wrap: conditionally wrap stuff with tags and labels

This is a fantastic plugin, thanks!
I’m having a little trouble getting it to work with image captions, though. In a form, I have:

<txp:smd_wrap transform="textile" wraptag="p" class="caption"><txp:image_info type="caption" escape="" wraptag="" /></txp:smd_wrap>

The textile function works perfect, but it’s not being wrapped properly. What I end up with is:

<p class="caption"> </p><p>[IMAGE CAPTION]</p><p> </p>

What am I doing wrong?

Offline

#20 2011-12-04 23:18:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,620
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

des wrote:

The textile function works perfect, but it’s not being wrapped properly. What I end up with is:
<p class="caption"> </p><p>[IMAGE CAPTION]</p><p> </p>

I see this too. At least in Firebug I see that structure, although looking at View Source I see the HTML is actually rendered “correctly” like this:

<p class="caption">	<p>[IMAGE CAPTION]</p></p>

The trouble is that you can’t wrap a paragraph with a paragraph. Semantically, how would a browser — or even a book — render a paragraph of text and then put another paragraph inside that one? Since Textiling content will always wrap paragraph tags around its content — unless that content has been told to ignore textile by use of ==, notextile. or spaces at the start of the line — there’s not much you can do.

My suggestion to get round this is by using wraptag="div" in smd_wrap or just not using a wraptag at all. Sorry, but I hope that helps.

Last edited by Bloke (2011-12-04 23:19:24)


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