2

I have developed a classifieds ads website using joomla, with my main component being dj-classifieds. I am now want to use addthis sharing tools. for this, I need to include the facebook title tag in the head of my website. the title of course is dynamic and I need to use a php string to get the correct title for each page. I was able to do this inside my source file that control the item view page. indeed, using <?php echo $item_name ?> inside my source file, I can display the title anywhere on the item view page.

What I trying to do is to generate the same title, but inside the file that controls my site's head. both file are located in different direction as follows (complete path, in the root directory): - item view source file is stored here : /components/com_djclassifieds/views/item/tmpl/default.php

  • the head file is stored here: /templates/jm-joomclassifieds-ef4/tpl/blocks/head.php

After reading various solutions, I decided to include default.php file inside the head.php file and then to call echo, but it did not work.

This is my code: <meta property="og:title" content="<?php include( $_SERVER['DOCUMENT_ROOT'] . '/components/com_djclassifieds/views/item/tmpl/default.php' ); echo $item->name; ?>" />

What am I doing wrong? I am rather very new with php, so I will dearly appreciate if you can be explicit in your help.

for further detail, below is and exrtact of of each of the two files:

  • the item view cource code (default.php: the extract below is from the beginning of the file up to the point where echo is called to generate the item title):

screen shot of the default.php extract

And this is the og tags that I am trying to write: ain the head.php file :

<!-- for Facebook -->          
<meta property="og:title" content="<?php include( $_SERVER['DOCUMENT_ROOT'] . '/components/com_djclassifieds/views/item/tmpl/default.php' ); echo $item->name; ?>" /> 
<meta property="og:url" content="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>" />

I will dearly appreciate the time that you will spend helping me out.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
  • Not sure but this might be of some use - perhaps Sourcerer might be helpful if you are struggling http://stackoverflow.com/questions/34363297/joomla-php-within-sourcerer-not-displayed/34366700#34366700 Maybe you could use sessions and make it a session variable so it would be available in a wider scope? `session_start();` at the top of the first part of the header and `$_SESSION['item_name'] = $item->name` at a point where you have access to it. – Steve Jan 14 '16 at 10:58
  • Thanks sa lot. I will try Sourcerer and keep you posted. – user5788232 Jan 14 '16 at 17:57
  • I think the session variable would solve your immediate problem though. Let me know if it doesn't work for you and I will try to shed some light if I can. – Steve Jan 14 '16 at 18:31
  • Nice little tutorial on sessions http://www.w3schools.com/php/php_sessions.asp It would be fairly simple - it may also be that sessions are already started in your system so you'd only need to add `$_SESSION['item_name'] = $item->name;` after where it says `$item = $this->item;` It may be that you would need to move the `include "default.php";` script up into the head and include it in the head or that value will not available until default.php has been loaded. Then when you have got the value just echo that as a php slug `name; ?>` in your content meta like in default.php. – Steve Jan 15 '16 at 15:41

0 Answers0