Forum

Thread tagged as: Question, Problem, Configuration

Full page URL as php variable into template

I've got this to collect the full URL..

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>

And this outputs the currect URL into the page.

<?php
  echo curPageURL();
?>

I need this variable in my template bride-detail.html to create some social sharing buttons.

How can I do this?

David Owen

David Owen 0 points

  • 5 years ago

Yes I know and this does work using plain text but not using a php variable.

<?php
    PerchSystem::set_var('lang', 'en');
    perch_content_custom('Brides', array(
        'template'=>'bride-detail.html'
    ));
?>

Assumes 'en' is manually added text wheres I need to add a php variable. In which case the template spits out for me"$myurl" I need the full URL in 'en'.

How can I do this?

Try:

<?php
$curPageURL = curPageURL();
PerchSystem::set_var('curPageURL', $curPageURL); 
perch_content_custom('Brides', array( 
  'template'=>'bride-detail.html' 
));

...and in template use <perch:content id="curPageURL" />

I think that's got it. I need to test.