Support > Elxis 4.x/5.x DEV

Howto retrieve meta keywords

(1/2) > >>

fgijsels:
Several weeks I try to solve a problem, without finding a real solution.

I work on a template for my website.
I want to retrieve the meta keywords in \index.php, but not with $eDoc-> showHead().
I have tried in different ways in a function in "\includes\hygieia.class.php" and in a function at the end of the "\index.php". Here I have found no way to retrieve the meta keywords.

The only way I have found to retrieve the meta keywords is to place the following code in "\index.php":

$eDoc = eFactory::getDocument();
$keywords = $eDoc->keywords;

<html <?php echo $eDoc->htmlAttributes(); ?>>   
   <head>
      ...
      <? php test1($keywords); ?>
      ...
   </head>
</html>

function test1(&$keywords){
      if (count($keywords) > 0) {
         $str = eUTF::str_replace('"',"'", implode(', ', $keywords));
         $html .= "\t".'<meta name="keywords" content="'.$str.'" />'."\n";
      }
      echo $html;
}

My questions:
Keywords is a private variabele In class elxisDocument (\inetpub\wwwroot\includes\libraries\elxis\document.class.php), so i do not understand wy this code works.
Is it safe to do it like this?
Are there beter ways to retrieve the meta keywords tag?

datahell:
Are you sure this code works? As you said keywords is a private variable. I will see it in the afternoon and answer you again but as far as I remember you cannot get the meta keywords, you can only set them.

fgijsels:
I could not figure it out. I thought that by changing and trying code (while searching for a solution to my problem), something gets messed up somewhere in the elxis code.

That is why I have performed a completely new elxis installation.
The code (as I put it on the forum) pasted into template.
And it still works!

datahell:
You made a big discovery! I haven't noticed that before. Private variables work because you actually work within elxisDocument class! So, you can access keywords directly: $eDoc->keywords. I have to say that I dont like that but it works...

webgift:

--- Quote from: datahell on June 08, 2018, 20:10:27 ---
Private variables work because you actually work within elxisDocument class!

--- End quote ---
I feel the same as i don't like it either :D

Navigation

[0] Message Index

[#] Next page

Go to full version