How to manage the variable of the webpage template? - template-engine

Because of the complexity of the existing webpage templates, I am trying to develop my own template engine with both easier syntax and the function I need.
When implementing the function of "include an other template", I began to wondering how to manage the variables in the included template, and those in the template included deeper.
It seems that adding some prefix to manage the namespace is to solve the problem, but I think it makes the variable names too long.
So how can I manage them in a good and simpler way?

Related

Is there any way to convert html template to liferay theme?

Is there any way to convert html template to Liferay 6.2 theme ? Is Alloy UI help me about this ?
There is no "one-click" tool to convert an html template to a liferay theme. You have to implement the theme yourself and use the "diff" folder to configure your own custom templates (.vm), scripts (.js) and styles (.css). Check out the official docs:
https://www.liferay.com/documentation/liferay-portal/6.2/development/-/ai/creating-themes-and-layout-templates-liferay-portal-6-2-dev-guide-09-en
https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/creating-liferay-them-7
+1 for Artem's answer which gives you the correct answer to your question. As a "no" might not be what you were looking for, let me add some reasoning extra - why would such a tool be introducing even more work later in the game?
If you look at the basic structure of Liferay's HTML code - all the nested divs, classes and ids - you'll find that they're quite clean and structured. A lot of Liferay's functionality is implemented with this kind of DOM in mind. If you'd introduce your own, completely unrelated, DOM from your own template, you'd need to find all components in Liferay that assume a certain structure. For example Layout Templates: They define "drop zones" where you can add portlets to the page. You probably don't have them in your existing templates. Another example: Maximized portlets. They'll need a DOM element to go into.
IMHO you're a lot better of to stick very close to the original DOM and just tweak your CSS to address the classes/elements you need. This is, of course, just a very general recommendation - for certain usecases this approach might also be a disadvantage. But most of the standard usecases are covered IMHO

Can I compile an Area and use the dll as a module for multiple sites?

I am trying to find out if I am thinking about this correctly. My goal is to be drop in a dll and have access to helpers, and partial views (Maybe Views too), using an MVC pattern. I have been treating Areas as modules lately using #RenderAction to serve me up some partials when I need them anywhere on a site. I can copy that whole area out and reuse it on another site, but that means changing namespaces on each file and it's duplication of the area so I am not getting to update it in one place for all sites. I am open to ideas and thoughts if I am approaching this incorrectly. For clarity's sake, here is my question: Is there a way to isolate only an area and compile it in it's own assembly? If so why is there not a new project type for that? Like add->new->module?
Thanks
You may checkout the following article which illustrates a nice technique allowing you to embed razor views into a separate assembly as embedded resources.

How to setup CodeIgniter for a truly multi language website?

I need to setup CodeIgniter to be a truly multi language website. I've searched but I can't find a solution.
I've tested this approach but it is not working. (http://codeigniter.com/wiki/Category%3AInternationalization%3A%3AInternationalization_Views_i18n/)
Can someone give me a clue about what setup to use to get a truly multi language environment in CodeIgniter?
Best Regards,
https://github.com/EllisLab/CodeIgniter/wiki/CodeIgniter-2.1-internationalization-i18n
If you implement this, you URLs will contain the language code. You can save your language parts in the language directory. With the function lang();
Loading language files and handling them is explained here:
https://www.codeigniter.com/user_guide/libraries/language.html
The helper:
https://www.codeigniter.com/user_guide/helpers/language_helper.html
Easiest way is have to some global language files which you auto load. I suggest creating a language file for every controller. So you only load the part you need instead of loading all language files.
From what I have learned. Building your own libraries and modules to handle them is a key. I haven't had much success with the native support as its a bit tricky sometimes. But basics to it is you have your default site load with the options to choose a language of your choice where within the site you echo out variables instead of static text. Those variables are then stored in what you can call a language pack. Where you have the same variables per language pack but the translated version per pack language. With code igniter it might be a bit more difficult then just appending to your url an identify for any given other language ie: mydomain.com/en/ mydomain.com/it/ mydomain.com/fr/ and then having a language load based off the URL like that however you can use CI's built in session support to store which language should be displayed. And based off of that display the choosen language I know thats not a super dead on answer how to do it, but this is how I would handle it should I ever get a project where I want multi language support.

How to make inheritance template in Pyrocms?

Pyrocms is using Dwoo template engine.
In Dwoo, we can make inheritance template.
{extends "default.html"}'
but, I can't do this in pyrocms that using Dwoo.
That wouldn't work. We only use Dwoo to allow dynamic syntax in the themes and written content.
What are you trying to achieve? The idea is you make multiple layouts and any shared content is put into partials, then you can load them using {theme_view('partialname')}
All of that stuff is a bit of a mess in v0.9.9.7, we've cleaned up the themes and syntax a LOT for v1.0 :)

Smarty integration into the CodeIgniter framework

A Little Background Information:
I've been looking at a few PHP framework recently, and it came down to two. The Zend Framework or CodeIgniter.
I prefer CodeIgniter, because of its simple design. It's very bare bone, and it is just kept simple. The thing I don't like though is the weak template system. The template system is important for me, because I will be working with another designer. Being able to give him a good template system is a big plus.
Zend was the second choice, because of the better template system that is built in. Zend is a different beast though compared to CodeIgniter. It emphasis "loose coupling between modules", but is a bigger framework. I don't like to feel like I have many things running under the hood that I never use. That is unnecessary overhead in my opinion, so I thought about putting a template system into CodeIgniter: Smarty.
Question(s): How easy/hard is the process to integrate Smarty into CodeIgniter? From my initial scan of the CodeIgniter documentation, I can see that the layout of the framework is easy enough to understand, and I anticipate no problems. I want to know if anyone has used it before, and therefore are aware of any "gotchas" you my have experienced that is going to make this harder than it should be or impossible to pull off. I also want to know if this is a good thing to do at all. Is the template system in CodeIgniter enough for normal use? Are there any other template modules that are good for CodeIgniter aside from Smarty? I better off with Zend Framework? Is any wheel being invented here?
Sorry to resurrect an old question - but none of the answers have been flagged as "accepted" yet.
There's a library called "template" that does a great job of allowing you to use just about any template parser you want:
Template CI Library - V1.4.1
The syntax is pretty easy for integrating into your CI application and the smarty integration spot on.
Slightly OT, hope you don't mind...
I'm a Zend Framework user and I think it's worth saying that the loose coupling means you don't need to include any files you're not actively using. Hopefully this negates your concern about unnecessary overhead.
With the layouts stuff added in a recent release of ZF, its templating is really hard to fault... and it's completely pluggable as Favio mentions. The more I use ZF, the more I like it; they do things the way I would do them!
I did a quick google search and found the following:
http://devcha.blogspot.com/2007/12/smarty-as-template-engine-in-code.html
http://codeigniter.com/forums/viewthread/67127/
If the designer is not familiar with Smarty, I think it's almost the same as if you use the existing CodeIgniter templating system (which leaves everything to PHP actually). It also depends on the complexity of the project at hand.
You can also hook Smarty with Zend Framework. It's more complex than with CodeIgniter, but there's already a primer on how to do exactly that in the ZF documentation. http://framework.zend.com/manual/en/zend.view.scripts.html Plus lots of tutorials on the net.
In my opinion it's almost the same, you can use pure PHP or Smarty as your template "engine", so it depends on the project. Also, compare a developer who has extensive experience and already has a library of view helpers so she uses pure PHP, versus a designer who doesn't know anything about PHP, but has extensive experience with Smarty. Sometimes decisions have to be based on who is going to do what.
Check out this custom CodeIgniter templating library. I've already used it on several projects and it is easy to use. I know this post is late but it's worth checking out.
It doesn't appear there has been an answer selected for this question nor has an up-to-date solution been given to work with the latest version of Codeigniter (2.0) and the latest version of Smarty (3.0.5).
This library allows you to use Smarty 3 with Codeigniter 2.0 so you can use Smarty 3 specific features like template inheritance.
http://ilikekillnerds.com/2010/11/using-smarty-3-in-codeigniter-2-a-really-tiny-ci-library/
Integrating Smarty in CodeIgniter? It is a breeze!
The template system in CodeIgniter is very basic.
Follow these steps for Smarty 3 in CI 3:
Download CodeIgniter 3
Download Smarty 3 and put its content in 'application/third_party/smarty' folder
Create 'Custom_smarty.php' file in 'application/libraries' and add this code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(APPPATH.'third_party/smarty/Smarty.class.php');
class Custom_smarty extends Smarty {
function __construct()
{
parent::__construct();
$this->setTemplateDir(APPPATH.'views/templates/');
$this->setCompileDir(APPPATH.'views/templates_c/');
}
}
?>
Create 'templates' & 'templates_c' folders inside 'application/views' folder
Create simple 'test.tpl' file in 'application/views/templates' folder
Open 'autoload.php' in 'application/config' folder and add:
$autoload['libraries'] = array('custom_smarty');
And inside a controller: $this->custom_smarty->display('test.tpl');
If you are working on localhost set the permissions: sudo chmod -R 777 templates_c. Otherwhise contact your hosting service, if you catch the error Unable to write file. First be sure templates_c folder exists.
Otherwise you can use another template engine like Twig.

Resources