3215 Posts in 848 Topics by 811 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1020 Views |
-
Noob question: Simple PHP functions

3 December 2010 at 11:19pm Last edited: 3 December 2010 11:20pm
Hi all,
I just started building a page with SilverStripe and I really have no idea about calling a php-function with return values....
My goal is to validate the generated html code to xhtml 1.0 strict.
So I just did this:
mycode/ArticlePage.php:
class ArticlePage extends Page {
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Downloads', new HTMLEditorField('download','Downloads'));
}
function valideLinks($data) {
$data = str_replace('target="_blank"','',$data);
return $data;
}
}themes/.../ArticePage.ss:
<div class="downloads">
$valideLinks($download)
</div>RESULT:
Parse error: syntax error, unexpected T_STRING, expecting ')' in /tmp/......templates.Layout.ArticlePage.ss on line 110So how can I call a php-function, to pass values and get return values?
Thanks in advance
-
Re: Noob question: Simple PHP functions

3 December 2010 at 11:26pm
remove the $ in front of valideLinks in the template
-
Re: Noob question: Simple PHP functions

4 December 2010 at 12:11am
Well, that generates this output:
<div class="downloads">
valideLinks(<ul><li><a title="pdf-Datei zum Herunterladen" href="assets/Uploads/kooperationsvertrag.pdf" target="_blank">Kooperationsvertrag</a></li>
</ul>)
</div>Not what I want.
-
Re: Noob question: Simple PHP functions

4 December 2010 at 2:09am Last edited: 4 December 2010 2:11am
Ok another try:
templates:
<div class="downloads">
<% valideLinks($download) %>
</div>output on html:
<div class="downloads">
<% valideLinks(<ul><li><a title="pdf-Datei zum Herunterladen" href="assets/Uploads/kooperationsvertrag.pdf" target="_blank">Kooperationsvertrag</a></li>
</ul>) %>
</div>BTW: the str_replace-function doesn't work too!
-
Re: Noob question: Simple PHP functions

4 December 2010 at 2:41am
you need to put the code into the template file directly and not via the TinyMCE...
-
Re: Noob question: Simple PHP functions

14 December 2010 at 10:35pm
I used the editor "nano" to edit the file, I also tried winscp, but the results are all the same:
<% valideLinks(<ul><li><a title="pdf-Datei zum Herunterladen" href="assets/Uploads/kooperationsvertrag.pdf" target="_blank">Kooperationsvertrag</a></li>
</ul>) %>I also rebuild the db and flushed the cache....any ideas? ;)
| 1020 Views | ||
|
Page:
1
|
Go to Top |

