We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Open Graph optimization: Current URL for template | Forum

Steve
Steve May 27 '14

Hey pals, im trying to add the following custom code to my oxwall template. The problem is that I can't find a variable that takes the current URL. I've tried with $smarty.get.url and others, but without success.


Anyone can help me please?


<meta property="fb:app_id" content="XXXXXXXX">

<meta property="og:url" content="{$SOME_VARIABLE}" />

<meta property="og:title" content="{$title}" />

<meta property="og:type" content="website" />

The Forum post is edited by Steve May 27 '14
Mohammad
Mohammad May 28 '14
Hello Steve,

Can't you just use JavaScript to get current URL ?

alert(document.URL)


or if you are making a plugin you can use this code :

$currentUrl = UTIL_Url::selfUrl();

and this is how you can pass it to view

$this->assign('url',$currentUrl);

in view use it like this :

<meta property="og:url" content="{$url}" />

The Forum post is edited by Mohammad May 28 '14
Steve
Steve May 28 '14
Thanks Mohammad! Im going to remember that. I ended messing with controller, because views in oxwall doesnt allow to put head content because its closed on master pages.


Another question. do you know which is .php controller for index page of oxwall? I want to add my custom headers as well.

Mohammad
Mohammad May 29 '14
Steve,Oxwall uses MVC,that's not work the way you think,there is no index.php,but Oxwall is the best,it gives you the ability to customize,for adding meta

you need to create a controller or use the one already exists

you need a method,lets call method name "head"

head() is like this:

head()

{

$document = OW::getDocument();$document->addCustomHeadInfo('<meta property="fb:app_id" content="XXXXXXXX">');

}

you can add as much as meta you need using $document->addCustomHeadInfo()

now create a method for binding head() in Oxwall event to run on every page

public function bindEvents()    { OW::getEventManager()->bind(OW_EventManager::ON_BEFORE_DOCUMENT_RENDER, array($this, 'head'));    }


now you need to open your init.php,it's because Oxwall checks init.php on every load,you should create an instance of your class,if you are using singlelton pattern you should do something like this :

PLUGINNAME_CTR_Filename::getInstance()->bindEvents();

or

create and instance directly

$ctrl = new PLUGINNAME_CTR_Filename();

$ctrl->bindEvents();


it' done,the meta you wanted now is it in <head> section.

FYI,if your plugin is not public and just yourslef using it,you can use admin Options,there is an option in admin area which allow you to add custom string info to head or body.you can get the parameter you want from JS

Steve
Steve May 30 '14
Awesome. Sure I know its MVC, im going to start working with this. 

If I end with some robust code, im going to share it here.


Thank you ver much Mohammad.

tammy harris
tammy harris Jun 8 '14
hi guys talking about current url i have been try every way i can think of 

to put current url into facebook comments  app
so it shows comments for each page 
if you put in www,yoursite.com     the comments are site wide same on every page 
i need to be able to put in www.mysite.com/curenturl
so will show only comments for each page 
Mohammad
Mohammad Jun 9 '14
Tammy,I told you last time,either you have to do it with JavaScript (or jquery) or making a plugin (second one does not make sense by the way)

you can get current full URL from JavaScript,you can insert it from admin area

do a little googling,maybe there are some good question on stackoverflow which can help you

tammy harris
tammy harris Jun 9 '14
i have tryed every way i have found in google but none work in oxwall 
i done in other scripts and works fine but oxwall has is own custom smarty thing that makes it hard 
some of them even crash the whole dam site or stop things like console things like friends request working or facebook send not works 
oxwall is so dam sensitive i cant even add shareoholic  stuff on the script stuff stops working
Mohammad
Mohammad Jun 9 '14
Tammy,you need to add this code in body section (not HEAD section ! careful!)


<script>
$(function() {
$('#fbshare').attr('data-href', document.URL);
});
</script>
<div class="fb-comments" data-width="570"
data-numposts="5" data-colorscheme="light" id="fbshare">
this is not the best way to add data-ST but I think it will do the job,plus this code is risk free

(this is what I remember from last time,the code you given to me)

The Forum post is edited by Mohammad Jun 9 '14
Micah
Micah Oct 16 '15
Steve, did you ever nail down some solid code for this?  I'd love to see what the end product of this was.