• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Add meta Property to Head from Fabrik Element?

talkinggoat

Member
I need to add a meta og:image property for facebook into the head of a page. Is it even possible to add elements to the head of a document from a Fabrik element or what is the best way? I can write it in Javascript, but it does no good, because Facebook scrapes the page before the JS has run.

Currently, I am adding the image into a textarea element and assigning it an ID tag of fb_image, to make things a little more dynamic.

Adding the meta in JS


JavaScript:
var fbImage = document.getElementById('fb_image').src;
var createMeta = document.createElement('meta');
createMeta.setAttribute('property','og:image');
createMeta.content = fbImage;
document.getElementsByTagName('head')[0].appendChild(createMeta);
 
Through form php plugin may be work properly. I use it in custom template.
PHP:
$metatitle = $this->data['table_name___meta_title_raw'];
$metadesc = $this->data['table_name____meta_description_raw'];
$metakeywords = $this->data['table_name___meta_keywords_raw'];
$image = $this->data['table_name___image'];
$mydoc = JFactory::getDocument();
$mydoc->setMetadata('title', $metatitle);
$mydoc->setDescription($metadesc);
$mydoc->setMetadata('keywords', $metakeywords);
$mydoc->setMetadata('og:image',$image, 'property');
 
Last edited:
Thank you. I set this to OnLoad in the Form's plugin section as PHP and it works wonderfully.


PHP:
$metaImage = $formModel->data["job_types___volunteer_application_image"]; //Gets the HTML for the image.
$metaDesc = $formModel->data["job_types___position_description"]; //Gets description.
$metaTitle = $formModel->data["job_types___position_title"];

if (isset($metaImage)){
  $doc = new DOMDocument(); //Parses the HTML.
  $doc->loadHTML($metaImage); //Inserts the HTML from the image.
  $xpath = new DOMXPath($doc);
  $src = $xpath->evaluate("string(//img/@src)"); //Strips out the src property of the image.
  $baseURL= JURI::base(); //Gets the base URL
    $src = $baseURL.$src; //Combines the base with the image URL.
  $mydoc = JFactory::getDocument();
  $mydoc->setMetadata('og:image',$src, 'property');
}

if (isset($metaDesc)){
  $mydoc = JFactory::getDocument();
  $mydoc->setDescription($metaDesc);
}

if (isset($metaTitle)){
  $mydoc = JFactory::getDocument();
  $mydoc->setTitle("Volunteer Wanted: ".$metaTitle);
}
 
Thank you for sharing your code. I was looking for it since long time.

$metaImage = $formModel->data["job_types___volunteer_application_image"]; //Gets the HTML for the image.

I have some listing which has just single Image and few have multiple images. How to modify the code to check whether if Image element contains single image or multiple images. If it contain multiple images, how to set it to pick up the First image ?
 
If it has multiple images, that's probably an array ...

Code:
if (is_array($formModel->data["job_types___volunteer_application_image"]) {
   // get first item from array
   $metaImage = reset($formModel->data["job_types___volunteer_application_image"]);
}
else {
   $metaImage = $formModel->data["job_types___volunteer_application_image"];
}

However, note that if you are using AJAX uploads, I have a feeling that $metaImage may itself wind up being an array of data (crop details, etc), rather than a simple path string. SO if the above doesn't work, try var_dump()'ing $metaImage and see what it is.

-- hugh
 
Can we insert dynamic meta Property to the Fabrik List through Php List plugin, if yes how ?
 
Code:
$data = $model->getData();
$city = $d->filters['property___city']->element;// Gets the Name of City from List filter.

if (isset($metaDesc)){
  $mydoc = JFactory::getDocument();
  $mydoc->setDescription("Check out best property from: ".$city);
}

if (isset($metaTitle)){
  $mydoc = JFactory::getDocument();
  $mydoc->setTitle("Top Properties from: ".$city);
}

I'm not sure, is this right code to have Meta data in Php Event List plugin 'onFiltersGot' ?

NB: Apologies for using this Thread instead of creating a new one. I feel, it makes more sense to have one Thread for Meta Data for Detail view and List are related. It would be easier to find others who are looking for same.
 
Unfortunately, the above code of Meta for List is not working!

Would appreciate any help in coding the correct php syntax to obtain Meta information for the List.
 
Metadata in list view:
Place metadata code in Php Event List plugin ->event->"onLoadData".
Metadata in list form/details view:
Place metadata code in Php Form plugin ->process script->"Before the form is loaded(OnLoad)".
 
Place metadata code in Php Event List plugin ->event->"onLoadData".

I tried, but no success. Maybe my following Metadata code for Event Php List plugin is wrong.

Code:
$data = $model->getData();
$city = $d->filters['property___city']->element;// Gets the Name of City from List filter.

if (isset($metaDesc)){
  $mydoc = JFactory::getDocument();
  $mydoc->setDescription("Check out best property from: ".$city);
}

if (isset($metaTitle)){
  $mydoc = JFactory::getDocument();
  $mydoc->setTitle("Top Properties from: ".$city);
}
 
I don't know is this code is a part of another code.
If not then you not have variables $metaDesc and $metaTitle.
Try to set metadata directly only with:
PHP:
$mydoc = JFactory::getDocument();
$mydoc->setDescription("Check out best property from: ");
 
I don't know is this code is a part of another code.
If not then you not have variables $metaDesc and $metaTitle.
Try to set metadata directly only with:
PHP:
$mydoc = JFactory::getDocument();
$mydoc->setDescription("Check out best property from: ");

This is working, BUT it is setting MetaData to both List and Detail view. I want to have different MetaData to ListView and Detail View.


PHP:
$mydoc = JFactory::getDocument();
$mydoc->setTitle("Check out best property from: ");

This is also working, BUT strangely it is setting MetaTitle to Detail view and NOT LIST view.
 
Set list metadata:
PHP:
$mydoc = JFactory::getDocument();
$mydoc->setDescription("Check out best property from: LIST");
$mydoc->setMetadata('title', 'mymetatitle');
//$mydoc->setTitle("Check out best property from: "); not working in list view
Try to clear your cache.
I don't have your problem
 
I my case, it sets title for Detail page instead List Page.

Where exactly are you using the code? Just "it's not working" isn't really useful.

If it's to show in a list, you may use the PHP Events List Plugin, as @startpoint already pointed out. Maybe try a different event.
Or, if you're using a custom list template anyway, add the code to its default.php. That's what I'm doing to add various stuff to <head>, and it works perfectly fine, of course.

BTW, you can also use
Code:
$metaTags  = '<title>Your page title</title>';
$metaTags .= '<meta name="description" content="'.$DescrVar.'" />';
$metaTags .= '<meta name="author" content="Your name here" />';

$mydoc = JFactory::getDocument();
$mydoc->addCustomTag($metaTags);
...in this example to add multiple different tags in one go. Trust you can mod it as you need.
 
Last edited:
Thank you for the reply and apologies for not explaining in detailed ( I mentioned my issue in couple of earlier threads just above my last one). @startpoint also pointed out in his last post that $mydoc->setTitle is not working at his end, unless I've not misinterpreted. Just to explain once again,

I have been trying to set MetaTags data to the FilterEvent with the help of Php Event List plugin ->event->"onLoadData".

I have F! List with multiple Hotels in different cities. I want to display dynamic MetaData based on City filter. For eg, if list is filtered to show Hotels from NewYork, it should show

$metaTags = '<title>Finds details of Best Hotels of NewYork</title>';
$metaTags .= '<meta name="description" content="'.$DescrVar.'" />';
$metaTags .= '<meta name="author" content="BlahBlah" />';
 
Ah, so your other or "real" problem is, for a list filtered by the user (not "pre"), to get the value of a particular list filter.

Haven't further investigated or even tested, but found this (thanks to the search function here... using it is highly recommended, hehehe):
In an element's default you can get a filter value via
FabrikHelperElement::filterValue(81); //with 81 = filter's element id

Here: http://fabrikar.com/forums/index.ph...data-cascadingdropdown-php.42105/#post-212897

Worth a try, me thinks.
 
We are in need of some funding.
More details.

Thank you.
Back
Top