Jump to:

3431 Posts in 1025 Topics by 864 members

Template Questions

SilverStripe Forums » Template Questions » Noob question: Simple PHP functions

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

Page: 1
Go to End
Author Topic: 1273 Views
  • rek
    Avatar
    Community Member
    4 Posts

    Noob question: Simple PHP functions Link to this post

    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

  • Banana
    Avatar
    Community Member
    18 Posts

    Re: Noob question: Simple PHP functions Link to this post

    remove the $ in front of valideLinks in the template

  • rek
    Avatar
    Community Member
    4 Posts

    Re: Noob question: Simple PHP functions Link to this post

    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.

  • Banana
    Avatar
    Community Member
    18 Posts

    Re: Noob question: Simple PHP functions Link to this post

    <% valideLinks($download) %>

  • rek
    Avatar
    Community Member
    4 Posts

    Re: Noob question: Simple PHP functions Link to this post

    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!

  • Banana
    Avatar
    Community Member
    18 Posts

    Re: Noob question: Simple PHP functions Link to this post

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

  • rek
    Avatar
    Community Member
    4 Posts

    Re: Noob question: Simple PHP functions Link to this post

    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? ;)

    1273 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.