17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1319 Views |
-
Coloring part of "Page Name"

22 September 2008 at 8:54pm
Hello,
I need to change the first word of Page name to what would be the best way of doing this? Is it possible to access the data, explode it and use a span to color it before it is passed to the view?
-
Re: Coloring part of "Page Name"

22 September 2008 at 9:04pm
Do you mean part of the title field on each page?
You can do this on your page_controller class in page.php
// override title from the database
function Title() {
$this->Title = ""; // explode , strip do whatever to add the <span> </span>
return $this->Title;
} -
Re: Coloring part of "Page Name"

22 September 2008 at 9:09pm Last edited: 22 September 2008 9:10pm
You could write a function in your Controller and call this function in your template.
function coloredPageName()
{
$parts = explode(" ", $this->Title);
$i = 1;
$newTitle = "<span>" . $parts[0] . "</span>";
while($i <= ($parts->Count() - 1))
{
$newTitle = $newTitle . " " . $parts[$i];
$i++;
}
return $newTitle;
}I didn't checked this code but it should work. You should be able to call the new Title with "$coloredPageName" in your .ss Template.
-
Re: Coloring part of "Page Name"

24 September 2008 at 2:44pm
Thanks for your help guys,
I'm having a few problems with the actual span output and with Count(),function Title(){
$parts = explode(" ", $this->Title);
$this->Title = "<span>" . $parts[0] . "</span>";
$i = 1;
while($i <= ($parts->Count() - 1))
{
$this->Title = $this->Title . " " . $parts[$i];
$i++;
}
return $this->Title;
}When I run this i get "Call to a member function Count() on a non-object", if I remove the while loop, to test if the first word is getting colorized, I get the output of <span>FirstWord</span> displayed on the page?
-
Re: Coloring part of "Page Name"

24 September 2008 at 2:48pm
Also when I tried adding color, "<span style="color:red;">" . $parts[0] . "</span>";
I get unexpected T_STRING, tried using different variations of " and ' to no avail -
Re: Coloring part of "Page Name"

24 September 2008 at 5:09pm
Thought I would post the solution we used for future reference
...controller...
function FirstTitle(){
$parts = explode(" ", $this->Title);
$startTitle = $parts[0];
return $startTitle;
}
function RestOfTitle(){
$parts = explode(" ", $this->Title);
$rest = array_shift($parts);
return implode(" ", $parts);
}...template...
<h1><span style="color:red;">$FirstTitle</span> $RestOfTitle</h1> -
Re: Coloring part of "Page Name"

24 September 2008 at 7:02pm Last edited: 24 September 2008 7:04pm
I get the output of <span>FirstWord</span> displayed on the page?
Use $coloredPageName.RAW instead. The "non-Object" problem should be fixed by writing a function into your model which returns the Title and change the
$parts = explode(" ", $this->Title);
with$parts = explode(" ", Model::TitleFunction());
Anyway, adding the HTML-Code to your Template is even better regarding to the MVC Design.
| 1319 Views | ||
|
Page:
1
|
Go to Top |


