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

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
Bealers

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

Post 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
Last edited by Bealers on Mon Jul 24, 2006 10:40 pm, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12709
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

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

Post by Dr.CSS »

And what do this spit out?
Bealers

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

Post 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
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12709
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

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

Post 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.
Bealers

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

Post 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
Post Reply

Return to “Tips and Tricks”