Just curious: are there cases in which these would return different results, or is the strip modifier a shortcut for the regex version?
<mt:Var name="test" strip="">
<mt:Var name="test" regex_replace="/\s+/g","">
Reported on Movable Type 4.2
Just curious: are there cases in which these would return different results, or is the strip modifier a shortcut for the regex version?
<mt:Var name="test" strip="">
<mt:Var name="test" regex_replace="/\s+/g","">
Reported on Movable Type 4.2
Hi Alex -
As you have it, the strip modifier won't do anything, because you have to provide something in order for it to work. Right now, you aren't passing anything in, so it will not execute at all. Typically you pass a value in and that value is then replaced.
Meanwhile the regex_replace modifier is used correctly - you are replacing all instances of multiple spaces with nothing.
You might want to look over the modifier documentation: http://www.movabletype.org/documentation/appendices/modifiers/
Hi Chad,
I was aiming in another direction with my question. To clarify, the results of the code examples are identical, whether you use strip or regex_replace. In both cases the modifiers modify "test" - whatever "test" holds. For example, it could be this:
<mt:SubCategories category="News">
<mt:SetVarBlock name="test" function="push"><mt:CategoryLabel /></mt:SetVarBlock>
</mt:SubCategories>
Since the results are the same, I was wondering why Six Apart created the strip modifier. Hence, my question. Do you still think the strip modifier has nothing to work on in the example?
Btw, I was looking for a way to strip whitespace that would leave any HTML tags intact, stripping only line breaks and other whitespace between text and HTML tags. That would involve a more complex regex with some sort of Lookaround I guess, but I can live without that for now.
Hi Alex -
In short, I'd say that the reason for the "strip" attribute is that it's a shortcut - a simpler way to get at the regex_replace function for most people, though it won't be as powerful. If you look at the code, you'll see that the routine used looks a lot like the regex_replace function.
But you don't have the trouble of creating a regex.
Still, what I said earlier holds - to some extent. The strip function only works if you assign a value - it won't work to replace with null (as you are doing). It's designed to replace whitespace with "something". The first thing it does is check for "something". If "something" is empty, then it sets "something" ($val) to a single space.
So in your example, the value of test (CategoryLabel) will be replaced with a single space. Meanwhile, using regex_replace should work the way you want - to replace CategoryLabel with nothing at all (or a string of whitespace as in your first example).
That means there is a difference - albeit a small one.