Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
Offline
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
Re: smd_wrap: conditionally wrap stuff with tags and labels
maniqui wrote:
adding support for
form
attribute andtxp: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
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?
Offline
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.
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
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
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 (iftrim
is used, which it is by default), parsed and then plugged into any<txp:yield />
in theform
. - if you use a pure container — no
form
oritem
— 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
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 theitem
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.
Offline
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
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
Online