我有一个html <h1 class="title">[VALUE]</h1>
,其中[VALUE]
在处理模板时被一些数据取代。
我想在php变量中使用取代[VALUE]
的数据。
像这样,$my_var = '[VALUE]';
function getHTML($articleid, $fieldid, $category = false, $write=false)
{
global $globalreturn;
//$str = fieldattach::getInput($articleid, $fieldid, $category);
$html ='';
$valor = fieldattach::getValue( $articleid, $fieldid , $category );
$title = fieldattach::getName( $articleid, $fieldid , $category );
$published = plgfieldsattachment_input::getPublished( $fieldid );
if(!empty($valor) && $published)
{
$html = plgfieldsattachment_input::getTemplate($fieldid);
if(fieldattach::getShowTitle( $fieldid )) $html = str_replace("[TITLE]", $title, $html);
else
$html = str_replace("[TITLE]", "", $html);
$html = str_replace("[VALUE]", $valor, $html);
$html = str_replace("[FIELD_ID]", $fieldid, $html);
}
//WRITE THE RESULT
if($write)
{
echo $html;
}else{
$globalreturn = $html;
return $html;
}
}
function getTemplate($fieldsids, $file="input", $valor)
{
global $globalreturn;
echo $valor;
$templateDir = dirname(__FILE__).'/tmpl/'.$file.'.tpl.php';
$html = file_get_contents ($templateDir);
$app = JFactory::getApplication();
$templateDir = JPATH_BASE . '/templates/' . $app->getTemplate().'/html/com_fieldsattach/fields/'.$file.'.tpl.php';
if(file_exists($templateDir))
{
$html = file_get_contents ($templateDir);
}
$app = JFactory::getApplication();
$templateDir = JPATH_BASE . '/templates/' . $app->getTemplate().'/html/com_fieldsattach/fields/'.$fieldsids.'_'.$file.'.tpl.php';
if(file_exists($templateDir))
{
include ($templateDir);
}
//return $html;
}
我试图使用$valor形式函数getHTML();在getTemplate()中;正如你将在上面的代码中看到的,我已经尝试调用global $globalreturn,然后调用echo $valor;
您可以尝试如下操作
我认为你想传递变量到另一个页面。因此在myfile.php
中添加以下代码 <h1 class="title"><?php define ( 'myVariable', '[VALUE]' ); ?></h1>
并在下一页使用require函数调用。
<?php
require("myfile.php");
?>