Zend include template file in another template - templates

I want to include a template file in another template file so I can get variable values.
Like I have two files _template1.phtml and template2.phtml
In _template1.phtml I have:
$this->text[] = 'Text here';
In template2.phtml I want to access the value of "text". I tried
$this->render('folder/template2.phtml');
var_dump($text);
var_dump($this->text);
but neither of this works.
What I need is _template1 file would be included from the template so the scope of $this would be the view object.
Thanks for any help.

Related

Intellij file template: how to set file name dynamically

I'm making a intellij template MyClassController but I want to insert just MyClass as name because I need to create thousands with same pattern.
I tried
package ...
#set($BASENAME = $NAME)
#set($NAME=${BASENAME} + "Controller")
#set($OBJNAME = $BASENAME.substring(0, 1).toLowerCase() + $BASENAME.substring(1))
import ...
but if #set($NAME= ... ) is present filename popup is not showing.
BASENAME's value (that is "") became NAME's value so my file end being named "$BASENAME" or "$".
There's a way to force name popup to appear or rename file after file is generated?

CLion new C++ Class file template

CLion has file template to generate C++ Class, which generates source file and header. In my project I have handler classes that have same code part, and i want to generate them by file templates. And templates that i created can't do this:
Set file names for class MyHandlerClass i want my_handler_class.cpp and .hpp
From one class name i want to generate 2 files header and source, don't know how to do that.
I also want to have string like MyClass -> my-class, found function $lowercaseAndDash($NAME) but don't know why its not works
I have template for header:
#pragma once
// includes
namespace handlers {
class ${NAME}: public Parent {
public:
// methods
};
}
I tried to solve first problem by setting the file name like this: #set ($FILE_NAME = "test_class.hpp"). But i don't know hot to set CamelCase to snake, and this don't works.
Also find in docs function to snake case, but its not works for me in file template.
Its impossible to change file name from template. When you create a C++ Class, you set class name and select file name encoding. When you create file from template its saves file with your file name. I found solution this way, enter file_name (in snake case), and with Velocity create CamelCaseName for class name:
#set( $CamelCaseName = "" )
#set( $part = "" )
#foreach($part in $NAME.split("_"))
#set( $CamelCaseName = "${CamelCaseName}$part.substring(0,1).toUpperCase()$part.substring(1).toLowerCase()" )
#end
Its impossible to generate 2 files from one click like it do C++ Class template. I have to templates, and use them both.
This function is for liveTemplates, for FileTemplate i used velocity: #set( $NeededString = $NAME.replaceAll('_', '-') )
To include header file from cpp use #[[#include]]# "${NAME}.hpp"

How to show another header template at home page?

I have get an header.twig file. I need to display this header template in home page differently than in others pages. How to do that?
Make two files, header.twig and home_header.twig
In catalog/controller/common/header.php there is a function index(), this uses header.twig
Write another method for example index_home() in header.php and copy the index() body in this function (make any changes if needed)
In index_home() change
return $this->load->view('common/header', $data);
to
return $this->load->view('common/home_header', $data);
If you check functions of every controller there is a line
$data['header'] = $this->load->controller('common/header');
this will call header.twig
Whichever function you need to use home_header.twig you can replace
$data['header'] = $this->load->controller('common/header');
in that function with
$data['header'] = $this->load->controller('common/header/index_home');
This will use home_header.twig

SugarCRM customization of Basic template

I need to add a field in basic template. Can anyone help me how can i add another field in include/SugarObjects/templates/basic/vardefs.php in upgrade safe manner.
In VardefManager's function addTemplate not like general standards of Sugar it is not requiring the custom paths
include/SugarObjects/VardefManager.php near line 107 SugarCE6.5.5:
if(empty($templates[$template])){
$path = 'include/SugarObjects/templates/' . $template . '/vardefs.php';
if(file_exists($path)){
require($path);
$templates[$template] = $vardefs;
}else{
$path = 'include/SugarObjects/implements/' . $template . '/vardefs.php';
if(file_exists($path)){
require($path);
$templates[$template] = $vardefs;
}
}
}
Really waiting for awesome responses.
Create a file at the path custom/include/SugarObjects/VardefManager.php with the name VardefManager.php and in that file include your mail file it is include/SugarObjects/VardefManager.php.
Here you will create a class with same and and create a function with the name
static function addTemplate
with same the arguments pass in the main file. and override the method here with your custom code (as you want to add some lines of code in that).
This will be upgrade safe and will be workable to you.

Codeigniter + Dwoo

I got problem when implementing my CMS using Codeigniter 1.7.2 and Dwoo. I use Phil Sturgeon Dwoo library. My problem is I want user create template from the admin panel, it means all template will be stored into database including all Dwoo variable and functions.My questions:
Is it possible to load dwoo template from database?
How to parse dwoo variable or function from database? I tried to load content from database which is include dwoo var and function inside it, and i have tried to do evaluation using dwoo eval() function and phil sturgeon string_parse() but still have no luck.
for example:
my controller
$data['header'] = "<h1>{$header}</h1>"; --> this could be loaded from database
$this->parser->parse('header',$data);
my view
{$header}
This is the error message:
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Undefined index: header_title</p>
<p>Filename: compiled/805659ab5e619e094cac7deb9c8cbfb5.d17.php</p>
<p>Line Number: 11</p>
header_title is dwoo variable that loaded from DB.
Thank you,
It is definitely possible to do this, but for performance reasons it would probably be faster to store the templates as files on the filesystem, even if they're edited by users. If you're smart with file naming you can avoid most hits to the database.
Anyway, if you really want to do it with the database, the following should work:
// rendering the header
$template = '<h1>{$header}</h1>'; // loaded from db, don't use double-quotes for examples or $header will be replaced by nothing
$data = array('header' => 'Hello'); // loaded from db as well I assume
$headerOutput = $this->parser->parse_string($template, $data, true); // true makes it return the output
// now rendering the full page (if needed?)
$data = array('header' => $headerOutput);
$this->parser->parse('header', $data); // no 'true', so goes straight to output
The view would then contain {$header} and the output from the header template is passed to that variable.
Now I'm not sure how CI works so it might be better to just output the result of the first template and skip the second one entirely, but I'll leave that up to you.