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
In the context to my post here
I will like to convert this:
<p>
property: value
property: value
property: value
</p>
Into this:
<p>
property: <span>value</span>
<br />property: <span>value</span>
<br/>property: <span>value</span>
<br/>a line without a colon
<br/>a line without a colon
<br/>property: <span>value</span>
</p>
And this is what I came up with which is working but not the best,
1. I’m pretty sure it can be done in a better way.
2. When a line doesn’t contains a colon, it is still adding a closing </span> tag,
which is not good cause there isn’t any open tag. (Should I use smd_if for this?)
<txp:smd_wrap transform="replace|string|<br />|</span><br />">
<txp:smd_wrap transform="split|:|: <span>|all, add|after|</span>">
<txp:php>echo nl2br(trim(custom_field(array('name' => 'extra_properties','escape'=>0))));</txp:php>
</txp:smd_wrap>
</txp:smd_wrap>
Will appreciate any help please.
Offline
Re: smd_wrap: conditionally wrap stuff with tags and labels
A typical, simple case: I was looking to join some variables with a comma, but only if variables returned something.
To my surprise, I couldn’t find a way to emulate adi_join using smd_wrap.
Unless I’m missing something not so obvious, in the smd_ Universe, this task (join stuff) seems a task more suitable for smd_each (optionally combined with smd_wrap if you want to wrap the whole output with something; for example, some parens ()).
Offline
#93 2012-10-24 20:47:41
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,316
Re: smd_wrap: conditionally wrap stuff with tags and labels
I’m trying to erase some typical “elbow on space bar” misuses, here: several tabs & spaces combos, and am getting an Unknown modifier '+' on line 203 error for this regex:
<txp:smd_wrap transform="replace|regex|[ \t]+|\t">
The only regex with a modifier in this topic is maniqui’s Ultimate Textilizer wrapper, which uses the plus like I do as far as I can see, but where is my fault? (v0.10 of smd_wrap)
Edit: Same error for {2,} which I should use actually ;)
Last edited by uli (2012-10-24 20:58:32)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: smd_wrap: conditionally wrap stuff with tags and labels
hi Uli.
The regex should be between two delimiters, I think. Like:
<txp:smd_wrap transform="replace|regex|#[ \t]{2}#|\t">
BTW, the Ultimate Textilizer wrapper snippet has some minor issues (which I can’t recall now) that I’ve to address… someday. But, overall, it works well in most situations, afaicr.
Offline
#95 2012-10-24 22:39:38
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,316
Re: smd_wrap: conditionally wrap stuff with tags and labels
Thanks, Julián, the errors are gone now, and parsed results finally show up :)
I’m an absolute beginner at regexes, I thought you had the # for Textile’s ordered lists in there. Are they common in regex land? (They aren’t in the help.)
Must admit that my small “knowledge” comes from the BBEdit manual, ATM, a Mac text editor for coding, which apparently has another syntax here and there. They use {2,} (no typo) for {2+} Edit: (Or is {2+} simply nothing? All the tabs still contained in the source code =p) So I have to experiment quite a lot and try and error. What better resources could I use as reference for working with smd_wrap, just Google for PHP regexes?
Last edited by uli (2012-10-24 22:49:00)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: smd_wrap: conditionally wrap stuff with tags and labels
uli wrote:
Thanks, Julián, the errors are gone now, and parsed results finally show up :)
Cool!
I’m an absolute beginner at regexes, I thought you had the # for Textile’s ordered lists in there. Are they common in regex land? (They aren’t in the help.)
Regex delimiters are common on regex land. I arbitrarely used #, but you can use other symbols, as long as you use the same at the very beginning and at the very end. Of course, you will have to escape the delimiter (like this, for example: \#) if, for some reason, you have to use it inside your regex.
What better resources could I use as reference for working with smd_wrap, just Google for PHP regexes?
I’d look into the PHP manual and I also usually look at www.regular-expressions.info/.
Finally, this recent thread at /r/learnprogramming on Reddit may provide you some useful resources too.
Offline
#97 2012-10-24 23:15:26
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,316
Re: smd_wrap: conditionally wrap stuff with tags and labels
Thanks for the links, Julían! Much appreciated.
On regular-expressions.info and some more regex resources I found the quantifier {2,} as the usual expression for 2 and more. Though, no matter what I use {2,}, {2,20} or {2,}? or even an apparently invented {2-20}, the errors reappear: this time No ending delimiter '#' . I’m pretty much at my wit’s end (in case I ever had some ;)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: smd_wrap: conditionally wrap stuff with tags and labels
Could you post the modified code? :)
Offline
#99 2012-10-24 23:21:44
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,316
Re: smd_wrap: conditionally wrap stuff with tags and labels
Sorry that I have to post only to be capable of thinking again: the error said it already, had to use a delim explicitly. D’oh!
After 1 am here, and still working, what should I expect.
Works now, thanks again, Julían!
Last edited by uli (2012-10-24 23:23:46)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#100 2013-12-12 18:57:01
Re: smd_wrap: conditionally wrap stuff with tags and labels
When using smd_wrap to format a date, it is defaulting to the timezone where my server is located instead of using the timezone that is set in my TXP installation preferences.
<txp:smd_wrap delim="@" transform="date|%B %e, %l:%M%P %Z"><txp:variable name="starttime" /></txp:smd_wrap>
The variable starttime = 2013-12-19T18:00:00-06:00
The above code outputs: December 19, 5:00pm MST However, I thought it would output to: December 19, 6:00pm CST
The server is in Orem, UT (MST), but my TXP installation is set to Chicago (CST).
Is it possible to adjust it to output for the time zone that is specified in TXP? Not sure if I’m just doing something wrong, if it’s a bug, or if I should be using another method to format the date?
Thanks in advance!
Last edited by photonomad (2013-12-12 18:57:39)
Offline
#101 2013-12-12 21:26:20
Re: smd_wrap: conditionally wrap stuff with tags and labels
photonomad wrote:
it is defaulting to the timezone where my server is located instead of using the timezone that is set in my TXP installation preferences.
This may well be a bug, depending on your notion of time. Would you mind trying something out for me please. Edit the plugin code, find this segment:
case 'date':
case 'time':
$nd = (is_numeric($out)) ? $out : strtotime($out);
if ($nd !== false) {
$out = strftime($xform[0], $nd);
}
break;
and replace it with this:
case 'date':
case 'time':
$nd = (is_numeric($out)) ? $out : safe_strtotime($out);
if ($nd !== false) {
$out = safe_strftime($xform[0], $nd);
}
break;
If that works and returns your local time then I’ll see if I can modify the date and time routine to allow you to pick which one you want to run (probably via another parameter).
Thanks.
Last edited by Bloke (2013-12-12 21:27: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
#102 2013-12-13 00:37:01
Re: smd_wrap: conditionally wrap stuff with tags and labels
Thanks for your reply, Bloke. I made the replacement that you suggested above. Unfortunately, it didn’t change the output. Darn. I thought safe_strtotime would’ve done the trick!
Offline
#103 2013-12-13 01:15:07
Re: smd_wrap: conditionally wrap stuff with tags and labels
I found a quick fix! Add the following line (with preferred timezone) to the plugin code:
date_default_timezone_set('America/Chicago');
I put it at the top, just after the start of the function:
function smd_wrap($atts, $thing=NULL) {
date_default_timezone_set('America/Chicago');
Reference: http://www.php.net/manual/en/function.date-default-timezone-set.php
Last edited by photonomad (2013-12-13 01:47:50)
Offline
#104 2014-02-15 10:55:29
Re: smd_wrap: conditionally wrap stuff with tags and labels
Stef, or anyone…
I’m using this variable to create figures/figcaptions. I’d like to use textile in the image caption, but I’m not sure where I’d add the transform wrapper, or if it can even been done in this case.
My guess would have been around the image_info tag as variable, value='<txp:image_info type="caption" />', but that didn’t work. (That’s just showing the location, not inclusion of the wrapper.)
Other possibility?
Offline
#105 2014-02-15 16:35:37
Re: smd_wrap: conditionally wrap stuff with tags and labels
Hi, Destry, Try this
<txp:smd_wrap wraptag="figcaption" attr="itemprop|caption" transform="textile">
<txp:image_info type='caption' />
</txp:smd_wrap>
Offline