Laravel包含一个具有动态价值的模板

时间:2018-04-04 19:24:20

标签: laravel blade

我想动态地包含一个模板,例如:<?php $strikes1 = null; $strikes2 = null; $strikes3 = null; $strikes4 = null; $strikes5 = null; $strikes6 = null; // // strikes and stations path // $strikes_dir= 'http://' . $username . ':' . $password . '@data.blitzortung.org/Data_' . $region . '/Protected/Strikes/'; $stations_file= 'http://' . $username . ':' . $password . '@data.blitzortung.org/Data_' . $region . '/Protected/stations.json.gz'; // // times // $end_time= time(); // // renew local data file // if (filemtime($local_strikes_file) < $end_time-60) { touch ($local_strikes_file); $l_time= $end_time-$time_span; $l_file= @fopen($local_strikes_file, 'r'); $t_file= @fopen($tmp_strikes_file, 'w'); while ($line= fgets ($l_file)) { $strike= json_decode($line); $strike->time/= 1000000000; if ($strike->time >= $end_time-$time_span) { fwrite ($t_file, $line); $l_time= $strike->time; } } fclose ($l_file); fclose ($t_file); rename ($tmp_strikes_file,$local_strikes_file); $run_time= $l_time; $l_file= @fopen($local_strikes_file, 'a'); while ($run_time < $end_time+600) { $filename= $strikes_dir . gmdate("Y/m/d/H/",$run_time) . $run_time/600%6 . '0.json'; if ($file= @fopen($filename, 'r')) { while ($line= fgets ($file)) { $json= json_decode($line); $json->time/= 1000000000; if ($json->time >= $l_time) { fwrite ($l_file, $line); } } fclose ($file); } else { $gzfilename= $strikes_dir . gmdate("Y/m/d/H/",$run_time) . $run_time/600%6 . '0.json.gz'; if ($file= @gzopen($filename, 'r')) { while ($line= gzgets ($file)) { $json= json_decode($line); $json->time/= 1000000000; if ($json->time >= $l_time) { fwrite ($l_file, $line); } } gzclose ($file); } } $run_time+= 600; } fclose ($l_file); } // // copy image // $img= imagecreatefrompng($map); $img_width= imagesx($img); $img_hight= imagesy($img); // // colors // $black = imagecolorallocate($img, 0, 0, 0); $white = imagecolorallocate($img, 255, 255, 255); $yellow = imagecolorallocate($img, 100, 255, 255); $orange = imagecolorallocate($img, 0, 200, 255); $red_light = imagecolorallocate($img, 0, 125, 255); $red = imagecolorallocate($img, 0, 50, 255); $red_dark = imagecolorallocate($img, 0, 0, 200); $white_10 = imagecolorallocatealpha($img, 255, 255, 255, 20); $yellow_10 = imagecolorallocatealpha($img, 255, 255, 0, 20); $orange_10 = imagecolorallocatealpha($img, 255, 170, 0, 20); $red_light_10= imagecolorallocatealpha($img, 255, 85, 0, 20); $red_10 = imagecolorallocatealpha($img, 255, 0, 0, 20); $red_dark_10 = imagecolorallocatealpha($img, 191, 0, 0, 20); $gray = imagecolorallocate($img, 143, 143, 143); $black_95 = imagecolorallocatealpha($img, 0, 0, 0, 95); $city_col = imagecolorallocate($img, 63, 63, 63); $active_col = imagecolorallocate($img, 63, 191, 63); $idle_col = imagecolorallocate($img, 191, 191, 63); $fault_col = imagecolorallocate($img, 191, 63, 63); $inactive_col= imagecolorallocate($img, 159, 159, 159); // // mercator projection // function mercator_proj ($lat) { $lat= (float)$lat; return(log(tan(pi()/4.0+$lat/2.0))); } // // draw strikes // $strikes= 0; $str_cnt= array (0, 0, 0, 0, 0, 0); $file= @fopen($local_strikes_file, 'r'); while ($line= fgets ($file)) { $strike= json_decode($line); $strike->time/=1000000000; if (($end_time-$time_span < $strike->time)&&($strike->time <= $end_time)&& ($west <= rad($strike->lon))&&(rad($strike->lon) <= $east)&& ($north >= rad($strike->lat))&&(rad($strike->lat) >= $south)) { $x= (int)(($img_width)*(rad($strike->lon)-$west)/($east-$west)); $y= (int)($img_width*(mercator_proj($north)-mercator_proj(rad($strike->lat)))/($east-$west)); if ($end_time-$strike->time < $time_span/6) { $str_cnt[0]++; $col= $white; } else if ($end_time-$strike->time < 2*$time_span/6) { $str_cnt[1]++; $col= $yellow; } else if ($end_time-$strike->time < 3*$time_span/6) { $str_cnt[2]++; $col= $orange; } else if ($end_time-$strike->time < 4*$time_span/6) { $str_cnt[3]++; $col= $red_light; } else if ($end_time-$strike->time < 5*$time_span/6) { $str_cnt[4]++; $col= $red; } else { $str_cnt[5]++; $col= $red_dark; } // // star // imageline ($img, $x-3, $y+0, $x+3, $y+0, $col); imageline ($img, $x+0, $y-3, $x+0, $y+3, $col); imagefilledpolygon ($img, array ($x-1, $y-1, $x+1, $y-1, $x+1, $y+1, $x-1, $y+1), 4, $col); // // square // // imagefilledpolygon ($img, array ($x-2, $y-2, $x+2, $y-2, $x+2, $y+2, $x-2, $y+2), 4, $col); // // ball // // imagefilledpolygon ($img, array ($x-1, $y-2, $x+1, $y-2, $x+2, $y-1, $x+2, $y+1, $x+1, $y+2, $x-1, $y+2, $x-2, $y+1, $x-2, $y-1), 8, $col); // // flash // // imagefilledpolygon ($img, array ($x, $y-10, $x+7, $y-10, $x+2, $y-3, $x+7, $y-3, $x-6, $y+10, $x-1, $y, $x-4, $y), 7, $col); // imagepolygon ($img, array ($x, $y-10, $x+7, $y-10, $x+2, $y-3, $x+7, $y-3, $x-6, $y+10, $x-1, $y, $x-4, $y), 7, $black); $strikes++; } } fclose ($file); // // draw stations /* $stations= 0; if (($gzfile= gzopen($stations_file, 'r')) != false) { while ($line = gzgets($gzfile)) { $station= json_decode($line); if ($station->station > 0) { if (($west <= rad($station->longitude))&&(rad($station->longitude) <= $east)&& ($north >= rad($station->latitude))&&(rad($station->latitude) >= $south)) { $x= (int)(($img_width)*(rad($station->longitude)-$west)/($east-$west)); $y= (int)($img_width*(mercator_proj($north)-mercator_proj(rad($station->latitude)))/($east-$west)); $col= $fault_col; if ($station->controller_status == "10") { $col= $inactive_col; } if ($station->controller_status == "20") { $col= $idle_col; } if ($station->controller_status == "30") { $col= $active_col; } imagefilledpolygon ($img, array ($x-3, $y-3, $x+3, $y-3, $x+3, $y+3, $x-3, $y+3), 4, $col); imagepolygon ($img, array ($x-3, $y-3, $x+3, $y-3, $x+3, $y+3, $x-3, $y+3), 4, $black); imageline ($img, $x-1, $y, $x+1, $y, $black); imageline ($img, $x, $y-1, $x, $y+1, $black); imagestring ($img, 2, $x+5, $y-15, $station->city, $white); $stations++; } } } gzclose($gzfile); } */ // // draw cities /* foreach ($cities_array as $city_line ) { $lat= strtok($city_line,';')*pi()/180.0; $lon= strtok(';')*pi()/180.0; $city = strtok(';'); if (($lon >= $west)&&($lon <= $east)&&($lat <= $north)&&($lat >= $south)) { $x= (int)(($img_width)*($lon-$west)/($east-$west)); $y= (int)($img_width*(mercator_proj($north)-mercator_proj($lat))/($east-$west)); imagefilledpolygon ($img, array ($x-2, $y-2, $x-2, $y+2, $x+2, $y+2, $x+2, $y-2), 4, $city_col); imagepolygon ($img, array ($x-2, $y-2, $x-2, $y+2, $x+2, $y+2, $x+2, $y-2), 4, $gray); imagestring ($img, 2, $x+5, $y-15, $city, $city_col); } } */ // // draw function // function draw_text ($img, $font, $x, $y, $text, $font_col, $bg_col) { if ($x < 0) { $x+= imagesx($img)-strlen($text)*7; } if ($y < 0) { $y+= imagesy($img)-13; } imagefilledpolygon ($img, array ($x, $y, $x, $y+12, $x+strlen($text)*7, $y+12, $x+strlen($text)*7, $y), 4, $bg_col); imagestring ($img, $font, $x, $y, $text, $font_col); } // // draw header lines // draw_text ($img, 3, 0, 0, "Blitzortung.org contributors, AOT", $white, $black_95); draw_text ($img, 3, -1, 0, date('Y-m-d T H:i:s',$end_time-$time_span), $white, $black_95); draw_text ($img, 3, -1, 26, sprintf ("Strikes:%5d",$strikes), $white, $black_95); // // draw legend // draw_text ($img, 3, 8, 24, sprintf (" %3d Minutes",intval(1*$time_span/6/60)), $white, $black_95); draw_text ($img, 3, 8, 37, sprintf (" %3d",intval(2*$time_span/6/60)), $white, $black_95); draw_text ($img, 3, 8, 50, sprintf (" %3d",intval(3*$time_span/6/60)), $white, $black_95); draw_text ($img, 3, 8, 63, sprintf (" %3d",intval(4*$time_span/6/60)), $white, $black_95); draw_text ($img, 3, 8, 76, sprintf (" %3d",intval(5*$time_span/6/60)), $white, $black_95); draw_text ($img, 3, 8, 89, sprintf (" %3d",intval(6*$time_span/6/60)), $white, $black_95); $x= 10; $y= 28; imagefilledpolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $white); imagepolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $gray); $y+= 13; imagefilledpolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $yellow); imagepolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $gray); $y+= 13; imagefilledpolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $orange); imagepolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $gray); $y+= 13; imagefilledpolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $red_light); imagepolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $gray); $y+= 13; imagefilledpolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $red); imagepolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $gray); $y+= 13; imagefilledpolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $red_dark); imagepolygon ($img, array ($x, $y, $x, $y+5, $x+5, $y+5, $x+5, $y), 4, $gray); // // draw statistics // function draw_statistic ($img, $font, $x, $y, $text, $width, $font_col, $bg_col) { if ($x < 0) { $x+= imagesx($img); } if ($y < 0) { $y+= imagesy($img); } imagefilledpolygon ($img, array ($x, $y, $x, $y-$width, $x+12, $y-$width, $x+12, $y), 4, $bg_col); imagestringup ($img, $font, $x, $y-$width+strlen($text)*8, $text, $font_col); } $x= 3; $y= imagesy($img)-4; imageline ($img, $x, $y, $x, $y-58, $white); imageline ($img, $x, $y, $x+81, $y, $white); $x++; $y--; if (($strikes1 < $strikes2)|| ($strikes1 < $strikes3)|| ($strikes1 < $strikes4)|| ($strikes1 < $strikes5)|| ($strikes1 < $strikes6)) { $strikes1= ""; } if (($strikes2 < $strikes3)|| ($strikes2 < $strikes4)|| ($strikes2 < $strikes5)|| ($strikes2 < $strikes6)) { $strikes2= ""; } if (($strikes3 < $strikes4)|| ($strikes3 < $strikes5)|| ($strikes3 < $strikes6)) { $strikes3= ""; } if (($strikes4 < $strikes5)|| ($strikes4 < $strikes6)) { $strikes4= ""; } if (($strikes5 < $strikes6)) { $strikes4= ""; } $max= 0; for ($i= 0; $i < 6; $i++) { if ($str_cnt[$i] > $max) { $max= $str_cnt[$i]; } } $str_cnt_disp= array ("", "", "", "", "", ""); for ($i= 0; $i < 6; $i++) { if ($str_cnt[$i] == $max) { $str_cnt_disp[$i]= $max; } } if( $max > 0) { draw_statistic ($img, 3, $x, $y, $str_cnt_disp[5], 55*$str_cnt[5]/$max, $white, $red_dark); $x+=13; draw_statistic ($img, 3, $x, $y, $str_cnt_disp[4], 55*$str_cnt[4]/$max, $white, $red); $x+=13; draw_statistic ($img, 3, $x, $y, $str_cnt_disp[3], 55*$str_cnt[3]/$max, $white, $red_light); $x+=13; draw_statistic ($img, 3, $x, $y, $str_cnt_disp[2], 55*$str_cnt[2]/$max, $white, $orange); $x+=13; draw_statistic ($img, 3, $x, $y, $str_cnt_disp[1], 55*$str_cnt[1]/$max, $black, $yellow); $x+=13; draw_statistic ($img, 3, $x, $y, $str_cnt_disp[0], 55*$str_cnt[0]/$max, $black, $white); } // // output image // header("Content-type: image/png"); imagepng($img); // // free memory // imagedestroy($img); ?>

但这会引发错误,我该怎么做? (如果我输出@include('{{ site('theme') }}.header'),则其值为{{ site('theme') }})。

提前致谢。

2 个答案:

答案 0 :(得分:0)

使用此:

@include(site('theme') . '.header')

答案 1 :(得分:0)

只需像php代码一样编写它。

@include(site('theme').'.header')