Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
HACK: Textile macros (sort of like MTMacros, baby)
Coming from MT, one of the things I missed were the Macros…
Some of my entries were full of things that used to be autoexpanded for me, and I didn’t want to go and manually fill them all back in – so, a little hack (and really, it’s little!) to classTextile, and I have roughly equivalent function to MTMacros – not quite as elegant, it’s not container tag replacement, and it’s not going to be able to swap out acronyms or any of that stuff.. but it will do handy string replacement (before Textile renders the page), and that’s what I really wanted it for…
I added this method:
<pre>
// ——————————————————————————————-
function preTextileMacros($text)
{
global $macros;
if ( isset($macros) && is_array($macros) )
{
$patterns = array_keys($macros);
$replace = array_values($macros);
$text = str_replace($patterns, $replace, $text);
}
return $text;
}
</pre>
to classTextile.php, and added this line:
$text = $this->preTextileMacros($text);
to the body of TextileThis (also in classTextile.php) right after the call to noTextile, and before the call to links, like so:
<pre>
$text = $this->noTextile($text);
$text = $this->preTextileMacros($text);
$text = $this->links($text);
</pre>
So, all you need to do is define a gloabl array called $macros someplace. Easiest: config.php, but I imagine I will eventually hack some way to get the array from the DB, so that you can maintain the array via the textpattern interface…
The array should look something like this:
<pre>
global $macros;
$macros = array (
‘textstringtoreplace’ => ‘text to replace string with’,
‘:)’ => ‘<img src=“smiley.gif” alt=”[:)]” />’,
);
</pre>
Last edited by ebullient (2005-02-06 00:33:23)
‘Waste of a good apple.’ – Samwise Gamgee
Offline
Re: HACK: Textile macros (sort of like MTMacros, baby)
I should have said something before so it didn’t look like i am just complaining, but anyways.
I really appreciate this hack, I use it for my class website so students can get their assignments etc. and it’s nice to use the macros for some default commnets and instructions.
That said, after I upgraded I tried to add this back into classTextile and it’s not working. Have you put this back into yours after the upgrade?
Offline
Re: HACK: Textile macros (sort of like MTMacros, baby)
I added this hack after the upgrade, I’ve even modified my hack since then.
To keep things current, I’ve added an entry to my site (yes, messy links, but – I know that id will be good no matter how many times I change my mind about category and section names..)
Update
This hack also works with TextilePHP, I’ve added notes to my page
Last edited by ebullient (2005-03-05 20:16:07)
‘Waste of a good apple.’ – Samwise Gamgee
Offline