Forum

Thread tagged as: Question

PHP Variables

Hello,

I am trying to put my page attribute outcome into a PHP variable, to use it elsewhere.

    $onderwerp = perch_page_attributes(array(
        'template' => 'onderwerp.html',
        'return-html' => true
    ));

This code automatically outputs the chosen page attribute, but using:

    echo $onderwerp;

I get nothing at all.

This returns only one output of the attribute:

    $onderwerp = perch_page_attributes(array(
        'template' => 'onderwerp.html',
        'return-html' => true
    ));
    echo $onderwerp;

So the attribute is not being saved in the variable, what am I doing wrong?

Thanks, Mike

Mike Hendriks

Mike Hendriks 0 points

  • 2 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Mike,

If you want to return the value of the rendered template (and assigning it to a variable), you need to set the second parameter to true:

$onderwerp = perch_page_attributes(array('template' => 'onderwerp.html'), true);

Ah ofcourse, was close but not close. Thank you, Hussein.