Forum
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?
You want this: https://docs.grabaperch.com/templates/passing-variables-into-templates/
Yes I know and this does work using plain text but not using a php variable.
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:
...and in template use
<perch:content id="curPageURL" />
I think that's got it. I need to test.