21298 Posts in 5735 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 643 Views |
-
Parse Menu Titles?

13 October 2010 at 8:09pm
Hi All!
This probably sounds like a stupid question, but I can't quite figure it out. Within a <% control Menu(1) %> control block, I need to parse each menu title, replacing any white spaces with non-breaking spaces ( ), and then return the result. I wrote a function in my page controller which uses PHP's str_replace method to do the job, BUT I can't figure out how to pass the current menu title to the function? Hope this makes sense. Any help or suggestions would be most appreciated!
-
Re: Parse Menu Titles?

13 October 2010 at 8:43pm Last edited: 13 October 2010 9:04pm
You don't need to create parameters to the method you just created on the controller, just create a method on the model class (Page) which parses the "Title" field from the database.
For example, in your Page model class (not Page_Controller):
<?php
class Page extends SiteTree {
...function CleanTitle() {
return str_replace(' ', '', $this->Title);
}...
class Page_Controller extends ContentController {
...Then you would simply use $CleanTitle inside the <% control Menu(1) %> block. This control loop iterates over Page instances, so you'll have access to any of the Page model fields and methods, including your newly created "CleanTitle".
Hope that explains it.
Cheers,
Sean -
Re: Parse Menu Titles?

13 October 2010 at 9:13pm Last edited: 13 October 2010 9:13pm
No problem, glad to see it's working for you.
| 643 Views | ||
|
Page:
1
|
Go to Top |


