Page 1 of 1

Modifying module or tag output without getting hands (too) dirty

Posted: Mon Jul 24, 2006 10:37 pm
by Bealers
Hi

It's a bit smelly but I had a 'quick win' requirement to munge the output from the menumanager into a number of fixed width columns. I've only ever used Smarty at it's simplest level so all I had to go on was the documentation on their website.

Long story short; the way I ended up doing this was by using a combination of Smarty's {capture} tag and Smarty modifiers, thus:

1) Embed code into template, wrapping the tag that you want to play with in the {capture} tags with the 'name' being the variable that collects the output. Then reference the variable but immediately pass the variable to a smarty modifer function, in this case menu_munge.

{capture name=specialMenu}
{cms_module module='menumanager' start_level='2'}
{/capture}
{$smarty.capture.specialMenu|menu_munge}

2) Create the modifer function in /lib/smarty/plugins/ called modifer.menu_munge.php

3) Fill it with something:
(.*?)\/",$string,$foo);
print_r($foo);
}
?>

Obviously that doesn't do much but you can see now that I have something to play with.

YMMV, works for me, etc

Re: Modifying module or tag output without getting hands (too) dirty

Posted: Tue Jul 25, 2006 3:56 am
by Dr.CSS
And what do this spit out?

Re: Modifying module or tag output without getting hands (too) dirty

Posted: Tue Jul 25, 2006 7:36 am
by Bealers
Hi
And what do this spit out?
Not sure what you mean. As in what was I trying to achieve, or what does my example do?

My example, doesn't actually do much, my point was that I was at the stage where I coudl do whatever I wanted.

In my case the designer had designed a second level nav that was in 3 columns, 4 rows per column. Menu manager's output is an unordered list as one would expect however I now wanted 3. Using the above I'm back to an array of links ($foo[1]) that I can iterate over and easily create 3 lists that I can float next to each other.

I can provide code and css if interested.

Cheers

Re: Modifying module or tag output without getting hands (too) dirty

Posted: Tue Jul 25, 2006 3:30 pm
by Dr.CSS
Oh i see, Cool.

I'm thinking you could have just made a new menu template and called it in your second level menu.

But I know nothing about Smarty.

I've made some that just output links without ul li and variations of this.

Re: Modifying module or tag output without getting hands (too) dirty

Posted: Tue Jul 25, 2006 3:39 pm
by Bealers
I'm thinking you could have just made a new menu template and called it in your second level menu.
I hadn't thought of that. Looking at the stock ones in /modules/MenuManager/tempaltes it looks like you're right, certainly less of a hack.

Still getting my head around the CMSms internals and it didn't hurt to learn some more Smarty. Maybe my method will be of use to someone in another context.

Cheers