PHP get current page URL

Permalink
I am setting up a page type with a default area for a Facebook share button. Instead of having to copy and paste the page URL each time into the widget, I would like for it to generate automatically. After some searching on the forums I tried this (in an HTML block):

<div class="fb-share-button" data-href="<?php echo $currentUrl; ?>" data-layout="button"></div>


And added this to the page template:
public function on_start() {
   global $c;
   $this->set('currentUrl',Loader::helper('navigation')->getCollectionPath($c));
}


But my text editor flags this and doesn't give any reason why, and it also breaks the page. Can anyone offer some suggestions? I would really appreciate it. Thanks

 
wilfordbrimley replied on at Permalink Reply
I am now also needing a way to get the current page URL for schema.org properties I'm adding to product pages. Any help is appreciated. I would consider paying for your time, thanks
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi wilfordbrimley,

What version of concrete5 are you using?

I think you could try this.
<?php echo $c->getCollectionLink(); ?>

- getCollectionLink() returns the full URL for the current page
ramonleenders replied on at Permalink Reply
ramonleenders
Try this:

$c = Page::getCurrentPage();
$this->set('currentUrl', $c->getCollectionLink());
wilfordbrimley replied on at Permalink Reply
Thank you both for responding. I simply cannot get this work with Facebook's button. It outputs the current page link as the PHP code. Here is info on the share button:https://developers.facebook.com/docs/plugins/share-button...

I am using 5.6.3.3. For now I have to go to the page properties and copy and paste the URL into the Facebook code for it to work - which is a major time delay! Any other thoughts on how to automate this would be greatly appreciated. Thanks
ramonleenders replied on at Permalink Reply
ramonleenders
OK, I re-read your post and you're putting this in an HTML block. That won't work. PHP ain't HTML! So you're going to have to create a block for this or some include.