PDA

View Full Version : Keyword - Description Variable


Rich
08-26-2012, 06:11 PM
I have a caresheet section that rests outside of vbulletin. It is integrated with vbulletin completely. I would like to be able to assign both keywords and a description within my caresheet.php files that are then used in place of the default vbulletin keywords and description I assigned for my website. I know I can use an if condition as described below to tell it when to use my keywords and description (tested - works) but I am trying to use a variable to assign the words themselves.

<vb:if condition="THIS_SCRIPT == 'careindex1' OR THIS_SCRIPT == 'careindex2'">
<meta name="keywords" content="{vb:raw mycarekeywords}" />
<meta name="description" content="{vb:raw mycaredescription}" />
</vb:if>

I would like to be able to set both the mycarekeywords and mycaredescription within the php file for each caresheet and have it used as the output but I am not succeeding and I think it is easier than what I have been trying. Any help would be appreciated. Thanks.

Rich
08-28-2012, 12:38 PM
I was hoping perhaps this wouldn't be that difficult to do. I could still use some help with this if anyone could steer me in the right direction.

kh99
08-28-2012, 01:10 PM
You would want to use register() or preRegister() to register the variables to the template. The difference is that register() needs to be called when the template is being rendered, where preRegister() can be called any time before. So it depends on how your code is set up. Assuming you're rendering your own template, you probably have something like:

$template = vB_Template::create('mytemplate');
// register variables here
$template->register('mycarekeywords', $mycarewords);
$template->register('mycaredescription', $mycaredescription);
print_output($template->render());


so you'd want to add those two middle lines.

Rich
08-28-2012, 02:58 PM
I am using an independant template system apart from vbulletin. I am using vbulletins header and footer which includes the navbar, notifications, etc. I was hoping to set mycarekeywords as a variable like:

$mycarekeywords = 'my keywords here';

and then have those keywords used in place of the sites default keywords when headinclude is called.

kh99
08-28-2012, 04:05 PM
OK, then try this: create a plugin using hook parse_templates code like this:

if (THIS_SCRIPT == 'careindex1' OR THIS_SCRIPT == 'careindex2')
{
$mycarekeywords = 'my keywords here';
$mycaredescription = 'mycaredescription';
vB_Template::preRegister('headinclude', array('mycarekeywords' => $mycarekeywords, 'mycaredescription' => $mycaredescription));
}

Rich
08-30-2012, 03:01 PM
Thanks Kevin and sorry for the delay in responding. That is how I am already doing it except directly in the headinclude template. Using the if condition I can simply assign the keywords in the template. I want to define the keywords and description in the file and have them passed over to the headinclude template as the file is called.

This would be the top of my PHP file:


<?php
define( 'THIS_SCRIPT', "templatetitle" );
$mycarekeywords = 'my keywords here';
$mycaredescription = 'my care description here';


Then when the file is called it pulls the data I entered as shown above and has that used as the output.

kh99
08-30-2012, 03:20 PM
OK, then take out where you set the variables and have it use globals instead, like:

if (THIS_SCRIPT == 'careindex1' OR THIS_SCRIPT == 'careindex2')
{
global $mycarekeywords, $mycaredescription;
vB_Template::preRegister('headinclude', array('mycarekeywords' => $mycarekeywords, 'mycaredescription' => $mycaredescription));
}


and of course change the check of THIS_SCRIPT if you need to. Or you don't really have to have the if statement at all. In scripts other than your, the variables will be undefined and will appear blank.

Rich
08-30-2012, 08:01 PM
Thank you very much Kevin! The globals worked wonderfully. I did omit the if condition within the plugin. I appreciate the help!