Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,452
Website GitHub

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.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

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

maniqui
Member
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
Member
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
New 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: 12,452
Website GitHub

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.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#21 2011-12-04 23:57:59

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,452
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

maniqui wrote:

<txp:smd_wrap form=“wrapcontent” transform=“replace||teapot|toaster”>I’m a little teapot</txp:smd_wrap>

Makes sense. Consider it done. At least, that construct now works in v0.11 beta but…

Should the wrapped content be processed before/after passing it to the specified form?

… does confuse things a little. However, I don’t think you have any real choice over parse order because the parser works on all form content at once, so there’s no way to defer processing of the yielded content after the form itself has been parsed.

In other words, the act of parsing the form parses any yield tags: if the yielded content contained any tags they would be parsed when the form was parsed!

The upshot is that the plugin logic is now:

  • If you use item it’s treated as ‘contained content’ but will NOT work with <txp:yield />. Container is ignored, thus a self-closing tag should be used.
  • if you use form you can also use a self-closing tag unless you want to use <txp:yield />.
  • if you use form AND a container, the contained content is trimmed (if trim is used, which it is by default), parsed and then plugged into any <txp:yield /> in the form.
  • if you use a pure container — no form or item — the contained content is treated as the data to wrap.

Note that in all cases except the last ‘pure container’ usage, you don’t get the benfit of being able to use <txp:else /> to show some other content if the data is empty.

[item attribute] 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

There’s not much in it, but I find this:

<txp:smd_wrap item="{my_smd_query_var}" wraptag="div" />

better than:

<txp:smd_wrap wraptag="div">
  {my_smd_query_var}
</txp:smd_wrap>

That was the only use case I could think of where the item is of practical use over container / form. It does make code shorter and more readable when nesting smd_wrap inside smd_query or smd_bio, for example, but it’s only useful if you want to silently ignore the times when the content is empty.

Last edited by Bloke (2011-12-05 00:27:32)


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#22 2011-12-09 23:08:07

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

Re: smd_wrap: conditionally wrap stuff with tags and labels

Bloke wrote:

Makes sense. Consider it done. At least, that construct now works in v0.11 beta but…

Thanks.

There’s not much in it, but I find this:
(…)
That was the only use case I could think of where the item is of practical use over container / form. It does make code shorter and more readable when nesting smd_wrap inside (…).

That explains it and I like it.

Another quick suggestion: experts (like me) in handling advanced smd_ technology will quickly grasp the plugin’s ins and out by just skimming over the plugin description, and one or two examples. But then, imo, the examples will be even more useful, particularly for newcomers to smd_ universe, if they include the expected output.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#23 2011-12-09 23:16:17

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,452
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

maniqui wrote:

the examples will be even more useful, particularly for newcomers to smd_ universe, if they include the expected output.

Good catch, thanks. I’ll add that to the docs before I release the next version officially. Just waiting on your report to see if the yield thing works for you.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#24 2011-12-09 23:36:52

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,202
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

Hi Stef,

been really putting this through its paces recently but I think I found something that smd_wrap can’t (yet) do … gasp … and that is formatting numbers.

I know php has number_format / money_format and that looks (to me) like a good fit for the plugin. How good is number_format at recognising inconsistently formatted numbers or does it have to have a pure number as input? As you know I’m drawing in values from a database that are inconsistently input by the respective operator, sometimes with a thousand separator, sometimes without, sometimes using the english decimal separator, sometimes not. I’m trying to get some consistent output out of the inconsistent db-data. I’m always pleasantly surprised at how well php’s date reformatting functions are able to recognise all manner of date formats and was wondering whether (read: hoping that) php’s number_format might be equally tolerant…


TXP Builders – finely-crafted code, design and txp

Offline

#25 2011-12-09 23:56:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,452
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

jakob wrote:

formatting numbers.

Good call. You can test it out if you like for now using smd_wrap’s custom ‘form’ transform:

<txp:adi_gps />
<txp:smd_wrap transform="form|wraptest">
   <txp:variable name="num" />
</txp:smd_wrap>

and in Form wraptest:

<txp:php>
echo number_format('{smd_wrap_it}', 2);
</txp:php>

Then just add ?num= to your URL and stuff values in to see the plugin render them to two decimal places. If it works to your satisfaction, let me know and I’ll add it as a transform.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#26 2011-12-10 00:13:21

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

YEAH! Thanks again Stef, this plugin (which I hadn’t spotted and luckily my friend Google had, I must be more observant1) has just saved my bacon.

I was using rss_auto_excerpt in an old site to build the meta description and then moved it to a new shiny server and the rss plugin broke :(

So I knee-jerk-switched it for rvm_substr, great but I was getting HTML in my meta description. And lo and behold, <txp:smd_wrap transform="strip_tags"> was there to save my bacon.

Looking forward to playing with more of the obviously powerful options provided by this plugin!

Thanks again! Cheers, -Alan

1 If you don’t minds me asking, if I want to stay in the loop with the latest new plugins from you and other top TXPers, where do you suggest I subscribe? A mailer somewhere, an RSS feed somewhere? I have a feeling the answer to this is embarrassingly simple…


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#27 2011-12-10 00:18:25

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,452
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

alanfluff wrote:

if I want to stay in the loop with the latest new plugins from you and other top TXPers, where do you suggest I subscribe?

Eventually you’ll be able to do it at textpattern.org. You probably can now actually, I’ve never tried using RSS there. But failing that, I’m pretty sure @textpattern gets updates from textpattern.org when new plugins are released there, though not new versions of old ones unless someone manually tweets about it.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#28 2011-12-10 00:19:37

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

Thanks Stef!


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#29 2011-12-10 00:45:13

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

Re: smd_wrap: conditionally wrap stuff with tags and labels

<txp:smd_wrap transform="form|wraptest">

Oh, I totally missed this when I asked for form/txp:yield combo support…
Stef, could you foresee any substantial difference between this transform="form|wraptest" and the form/txp:yield combo?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#30 2011-12-10 01:10:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,452
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

maniqui wrote:

any substantial difference between this transform="form|wraptest" and the form/txp:yield combo?

Probably some subtle differences. The ‘form’ transforms can be chained so they’re potentially more powerful than <txp:yield /> which only has one ‘level’. But transforms define things you do to your input data, whereas form/yield/container is stuff upon which transforms are applied. Admittedly the line is blurred a little because yield is data inserted at runtime, but the distinction between the two is probably still relevant. It’ll probably come down to whether the other attributes like trim, prefix and suffix are of use on the input data: they work differently to the trim and add transforms so your intended use may dictate which approach to use.

I would expect there are situations where one is more suited over the other so it’s handy having both available. Quite what those situations are I’m not sure, as that’s down to your level of deviousness at pushing and twisting plugins to do things they’re not explicitly designed to do. And I know you have a lot of that commodity in reserve ;-)

Last edited by Bloke (2011-12-10 01:12:41)


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB