Dynamic titles and meta tags in PHP project

Hello again.
Is there a guide on how to use dynamic titles and meta tags in a PHP project?

Wappler says yes “Server Data Binding are only available in NodeJS”

If I put the server connect in front of or in the , <script …> and <link …> are no longer output properly.

Many thanks for your help!

Good morning, you can create a class in php to bring the data in pure php

Example of class:

class Api {
function __construct(){
//session_start();

$url_dominio_completa = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
@$url_dominio = "http".(isset($_SERVER['HTTPS']) ? (($_SERVER['HTTPS']=="on") ? "s" : "") : "") ."://".explode('/', $url_dominio_completa)[0];

  define('HOME', $url_dominio);
  
}

public function productDetails($id)
{
    
    
	$api = HOME.'/dmxConnect/api/products/product_details_front.php?id='.$id;
  
	$ch = curl_init($api);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	$response = curl_exec($ch);
	curl_close($ch);
	$object = json_decode($response);

  	return $object->product;
  
  
} 

or

<?php

$base_url = https://www.yourdomain.com.br

$api = $base_url.'/dmxConnect/api/products/product_details_front.php?id='.$id;

$ch = curl_init($api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$object = json_decode($response);

return $object->product;

}
?>

1 Like

Not sure what you mean?
All you need to do is to switch the App Root from body to page:

Screenshot 2023-03-07 at 14.51.39

and then you can use dynamic data bindings in the meta tags as anywhere else on the page.

If it’s just to put dynamic data in the page header, just change the app’s structure as Teodor said, but that’s not rendered by the server, making the titles useless for sharing on social networks, unlike nodejs where we have the option to render on the server, in php we need to do what I put in the code, to create variables rendered by the server and not by javascript.

From what I understood, that’s what he was asking.

example <?= $title ?>

I’ve been trying in vain for 3 days to get a NodeJS page online without success.
That is to complicated for me.

I just want to dynamically generate the metadata for Google.

So …

I have now changed the app root to Page.
As you can see, only the title is dynamically generated but not the other metas.

Well you need to use dmx-bind:content="" in order to use dynamic data. And remove {{ }} around the expression. Example:

dmx-bind:content="scShowPage.data.queryShowPage.metaTitel"
1 Like

thank you very much, that works