Welcome,
Guest
.
Please
login
or
register
.
Did you miss your
activation email
?
News:
Elxis 5.5 Calypso supports 2 factor authentication login with e-mail or SMS.
Home
Help
Login
Register
Elxis CMS Forum
»
Support
»
Elxis 4.x/5.x DEV
»
Howto retrieve meta keywords
« previous
next »
Print
Pages: [
1
]
Author
Topic: Howto retrieve meta keywords (Read 8119 times)
fgijsels
Newbie
Posts: 15
Frank
Howto retrieve meta keywords
«
on:
June 08, 2018, 10:34:27 »
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?
Logged
datahell
Elxis Team
Hero Member
Posts: 10356
Re: Howto retrieve meta keywords
«
Reply #1 on:
June 08, 2018, 14:55:30 »
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.
Logged
Elxis Team
|
Is Open Source
|
IOS Rentals | IOS AERO
fgijsels
Newbie
Posts: 15
Frank
Re: Howto retrieve meta keywords
«
Reply #2 on:
June 08, 2018, 15:47:44 »
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!
Logged
datahell
Elxis Team
Hero Member
Posts: 10356
Re: Howto retrieve meta keywords
«
Reply #3 on:
June 08, 2018, 20:10:27 »
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...
Logged
Elxis Team
|
Is Open Source
|
IOS Rentals | IOS AERO
webgift
Elxis Team
Hero Member
Posts: 4193
Re: Howto retrieve meta keywords
«
Reply #4 on:
June 09, 2018, 18:07:31 »
Quote from: datahell on June 08, 2018, 20:10:27
Private variables work because you actually work within elxisDocument class!
I feel the same as i don't like it either
Logged
Elxis Team •
Custom web design [EN]
-
[EL]
•
.GR Registrar
fgijsels
Newbie
Posts: 15
Frank
Re: Howto retrieve meta keywords
«
Reply #5 on:
June 10, 2018, 18:05:24 »
finally found the following solution:
in C:\inetpub\wwwroot\templates\hygieia\index.php
...
elxisloader::loadFile('templates/hygieia/includes/hygieia.class.php');
$hygieia = new templateHygieia();
// display the document type before the html tag.
echo $eDoc->getDocType()."\n";
?>
<!-- Start html this way (elxis will append some attributes on the html tag) -->
<html <?php echo $eDoc->htmlAttributes(); ?>>
<head>
<?php $hygieia->getmetaKeywords($eDoc); ?>
...
</head>
...
</html>
in C:\inetpub\wwwroot\templates\hygieia\includes\hygieia.class.php
class templateHygieia {
/*********************/
/* GET META KEYWORDS */
/*********************/
public function getMetaKeywords($eDoc) {
$myReflectionClass = new ReflectionClass(get_class($eDoc));
$myProperty = $myReflectionClass->getProperty('keywords');
$myProperty->setAccessible(true);
$keywords = $myProperty->getValue($eDoc);
if (count($keywords) > 0) {
$str = eUTF::str_replace('"',"'", implode(', ', $keywords));
$html .= "\t".'<meta name="keywords" content="'.$str.'" />'."\n";
}
echo $html;
}
}
Logged
Print
Pages: [
1
]
« previous
next »
Elxis CMS Forum
»
Support
»
Elxis 4.x/5.x DEV
»
Howto retrieve meta keywords