Sorry for repeating, but I really really need to know:
How do you use variables within the regex_replace attribute??
The following works:
<mt:var name="body_content"
regex_replace="/<span class="mt-enclosure .+?><img
alt="(.+?)" .+?</span>/g","$new_image_block"
setvar="body_content" />
but I need to put the current asset's label* into that search text, like the following but I'd prefer something that actually works.
<mt:var name="body_content"
regex_replace="/<span class="mt-enclosure .+?><img
alt="$my_image_label" .+?</span>/g","$new_image_block"
setvar="body_content" />
That doesn't work, so can you please tell me what would? I haven't found a way of approaching this that doesn't involve me needing a variable in that search text.
* Yes, this is all within the context. I'm looking for the span that contains the current asset's label, and replacing that whole span with a different block of HTML.
Help, please!!
Reported on Movable Type 4.2
It doesn't appear that you can use variables in the regex_replace modifier (at least through my own tests as well as yours). You can use them in the regular 'ol replace modifier. Possibly if you set up more easily searchable conditions you could just use the replace modifier instead. It seems like it's touchy ground with regex_replace, since we know how much regex likes the $ sign, and how much MT likes it as well.
I could be wrong… but I could be right.
Thanks, Pedro. It's a good suggestion, but I'd need to know exactly what the span will be like for a given asset, and I don't -- in particular, I don't know what the width & height of the thumbnail will be.
If I could just find the spans and put them into a variable (or a variable array)... but I haven't figured that out yet, either. :-P
Well, if anything you could use some PHP or other alternative, unless the code you're trying to insert uses some MT tags or something like that.
Uh, crud, how do I do that? Nevermind, I'll look that up later.
mt variables worked for you within replace? It's failing for me. What am I doing wrong, please?
Sorry, Pedro, I shoulda said in what way it wasn't working: all of the asset labels are being replaced by "FNORDDRONF$my_asset_id" without that $my_asset_id being replaced by the actual id.
In my experimenting, you can't do that. You have to only have just the variable in there
If you wanted to modify that, you could set up a variable block to combine "FNORDDRONF" and the value of $my_asset_id. It would look something like this:
Oops, I had a typo in there. You don't need the quotes around "FNORDDRONF" in the variable block (that's what I get for copying/pasting). Variable blocks are smart enough to process everything in them like MT normally would and put all the returning values into the variable block - so you can put all sorts of code as well as plain text, and it'll just plow right through it.
You might want to run this scenario by the MTOS developer mailing list to see if this sort of scenario is supported by the template engine.
***If you do post it on the MTOS mailing list, and they say it is possible, it would be nice if you could take a few minutes to document what you tried to accomplish and how you did it so that others could benefit from more documentation.
Mike T, I'm not familiar with the MTOS developer mailing list, sorry.
http://www.sixapart.com/mailman/listinfo/mtos-dev
...
Thanks, Mike. But now that I re-read the thread, I'm wondering -- which scenario did you mean? I'm going to ask there about the scenario more fully fleshed out in my most recent question, but the scenarios here are, I think, confirmed:
In regex_replace, you can only use a variable as the replace pattern, not as the search pattern.
In replace, you can use a variable as either the replace or search texts, or both, but you have to just use a variable; "fubar$my_var" doesn't work. (Thanks, Pedro!!)
hope that helps someone.
Mike & Pedro & others, thanks for helping so much during this latest development rush/panic.