Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

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:

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

Txp Builders – finely-crafted code, design and Txp

Offline

#22 2011-12-09 23:08: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:

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: 8,620
Website

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.

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: 3,388
Website

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: 8,620
Website

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.

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: 221
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: 8,620
Website

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.

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: 221
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
Moderator
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: 8,620
Website

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.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB