Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Noob question: Simple PHP functions


Go to End


7 Posts   2835 Views

Avatar
rek

Community Member, 4 Posts

3 December 2010 at 11:19pm

Edited: 03/12/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 110

So how can I call a php-function, to pass values and get return values?

Thanks in advance

Avatar
Banana

Community Member, 18 Posts

3 December 2010 at 11:26pm

remove the $ in front of valideLinks in the template

Avatar
rek

Community Member, 4 Posts

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.

Avatar
Banana

Community Member, 18 Posts

4 December 2010 at 1:19am

<% valideLinks($download) %>

Avatar
rek

Community Member, 4 Posts

4 December 2010 at 2:09am

Edited: 04/12/2010 2:11am

Ok another try:

templates:

<div class="downloads">
<% valideLinks($download) %>
</div>

output on html:

<div class="downloads">
&lt;% valideLinks(<ul><li><a title="pdf-Datei zum Herunterladen" href="/assets/Uploads/kooperationsvertrag.pdf" target="_blank">Kooperationsvertrag</a></li>
</ul>) %&gt;
</div>

BTW: the str_replace-function doesn't work too!

Avatar
Banana

Community Member, 18 Posts

4 December 2010 at 2:41am

you need to put the code into the template file directly and not via the TinyMCE...

Avatar
rek

Community Member, 4 Posts

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:

&lt;% valideLinks(<ul><li><a title="pdf-Datei zum Herunterladen" href="/assets/Uploads/kooperationsvertrag.pdf" target="_blank">Kooperationsvertrag</a></li>
</ul>) %&gt;

I also rebuild the db and flushed the cache....any ideas? ;)