Haxe takes some templates to bin folder when it compiles. It process templates, replacing variables in it ::WIN_WIDTH:: with values 640. It can also take your custom templates like so:
<template path="your/template.txt" rename="tmpl.txt"/>
I would like to know is there any way to place your own variables ::myvar:: in those templates?
EDIT
http://old.haxe.org/doc/cross/template - Unfortunately, that article only explains how to execute haxe.Template class instances. In the end you will get the string (your processed template).
What I want is to add my custom placeholders to default haxe templates, such as OpenFL Android project templates. I need Haxe to process it's templates WITH my own placeholders and outputs it in the bin folder, as usually does.
I had to figure it out the hard way, but it turns out that the <setenv> tag really works as advertised.
In project.xml:
<setenv name="MY_VAR" value="612" />
In template.txt:
::if ENV_MY_VAR::
The value of MY_VAR is ::ENV_MY_VAR::.
::else::
MY_VAR is not defined.
::end::
You could also define it as "myvar", but then you'd have to use "ENV_myvar" in template.txt.
http://old.haxe.org/doc/cross/template
this explain everything about templates, how to use variables and things like if and foreach.
Related
I am using EmberJS with HandleBars and using the Yeoman setup, (but I updated dependencies to the latest).
I have a relatively large application.hbs, and I want to separate it into different files like top-bars.hbs and main-content.hbs and so on, then I want to include them in the application.hbs. but I do not have any views for them, just some separation of the big file, I do not want to make ajax requests for those templates, just want to separate and then include them.
How can I do this in emberJS?
I think what you maybe looking for is a partial. What you would do is make a partial file in the directory you want most likely somewhere with all the other templates. The resolver complains about either leading underscores or dashes in Yeoman so if one blows up try the other this is mostly for a visual indication when looking through your files which ones are partials. So make _top-bars.hbs and put the code you want in there. and the in the application.hbs just do `{{partial "top-bars"}} and it will put the template into the application template without changing the scope.
Hello everyone and thank you for taking time to read this.
I've been using Phalcon for quite a while for a high performance JSON/XML API.
The backend managing this application was/is still driven by an oudated version of symfony, but it is gonna be dropped in favour for Phalcon and the Volt Template engine.
Now my problem is the following:
Imagine a base application and a basic template and the application is modularized. Most modules are gonna be developed by different teams but they all have to integrate niceley, which from the program logic side is not a problem.
But imagine the following:
You have a simple page, some forms, head, navigation, etc, etc.
Now someone wants to add a module which injects a template block into the footer for whatever purpose. For example adding a TagCloud (for SEO purposes) into the footer.
The idea here is, that the plugin has way to edit any template files other than the ones it brings itself.
How can this be achieved without having to change the base templates after the initial development?
The idea is basically to hook into a event, lets call it TEMPLATE_RENDER for simplicity.
TEMPLATE_RENDER is fired, every listener that is registered for it now has its chance to add stuff to the template like additional blocks etc. All without having to manually change the core templates.
It would be sufficient if there is a way to simply add a bunch of template files together in Volt and output the compiled result.
EDIT:
Okay, after some thought what I'm looking for in Volt is this:
Compiler#compileMultipleFiles(String... files);
So it can be used like this:
$compiler->compileMultipleFiles('/path/to/template1','/path/to/template2', ...);
Which would do nothing else "in theory" than take everything in file1, file2, ..., fileN and put it into one large file and then compile that as a single template. If it is not yet possible I could emulate that function by simple having each files contents combined into a single file or cache variable and use compileString() but that would break any relative paths in the template, which would be a problem.
I could also compile each template down manually, but than I would end up with an pure html document without the ability to append to blocks in the main template.
Apparently there is no such function directly.
You can however use an array and iterate over this area at the end of the primary template and dynamically include any file passed into there.
I believe that you're looking for a Volt include. You can leave some tests in your templates like:
{% if foo.enabled %}
{% include "foo/bar.volt" %}
{% endif %}
If you need something more complex than this you can use template inheritance also.
i´m developing a theme and for some reason i need to move the default position for breadcrubms (also for many other things) over woocommerce themes. Then i realised to do something like this on my functions.php:
function woocommerce_remove_breadcrumb(){
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20);
}
add_action('woocommerce_before_main_content', 'woocommerce_remove_breadcrumb');
function woocommerce_custom_breadcrumb(){
woocommerce_breadcrumb();
}
add_action( 'woo_custom_breadcrumb', 'woocommerce_custom_breadcrumb' );
And then on any template file, output the breadcrumb just with:
<? do_action('woo_custom_breadcrumb'); ?>
And works. My question is more than that. Is this the correct approach for something like this? I mean for anything over woocommerce, not just breadcrumb, for any pice, ratings, titles, buttons, sidebar, and so on.
What i´m thinking on is why woocommerce templates don´t come with more deep code. I mean, why there´s no such a single-content-loop.php template where you can just change the order of things, title, category, content, images, etc. in an easy way rather that hooking into functions?
I think that is an acceptable way to call the breadcrumbs explicitly. Sometimes it is easier to call a specific function than remove everything around it!
As for changing the order of things and getting into advanced customization; there isn't a single file, but a number of files working together. Create a folder in your themes root called 'woocommerce' and copy the following files for a safe override:
woocommerce/woocommerce-hooks.php:
Here are your hooks, including the ones you are overriding in your themes functions.php. Here is where you can experiment with removing and repositioning certain elements on your product page. Search for 'Sidebar' and you will see where the 'woocommerce_sidebar' action is added with the function it references in...
woocommerce/woocommerce-template.php:
Here are the functions used in template files to output content based on conditional statements. For instance, search for the 'Single Product' series and you can see which template files are used for which functions. For instance 'woocommerce_template_single_title' uses 'single-product/title.php' - if you copy over this folder and file you can make very specific edits to just the title section
Between these two files and their accompanying references (like title.php) I believe you can do the things you described. Let me know how it works out! I'm new to woocommerce too!
I'm looking for a fast way to display a particular template file based on the current language of the page.
Let's say I have two languages : english and french (english being the default)
I have various templates files, like : page.tpl.php page-node-11.tpl.php in my theme directory.
I'd like to find out a way to include these files based on the current languages; so for example if the current language is 'english', it will include 'page.tpl.php', if the current language is 'french' it will include 'fr/page.tpl.php'.
I'm sure it's pretty straight forward, but can't figure out how; in template.php ?
Thanks for any help.
Assuming you're using the Internationalization module, rather than changing the template per language, you may want to consider taking advantage of the CSS class set on the body tag. I've used that technique on sites before and it was easier than dealing with another template file. If you don't use the i18n module, you could still add the body class inside a preprocess_page function.
If a body class won't work for you, you could look at the patch from the issue above for an example of how to add the language to the variables array during preprocessing. Then see the Working with template suggestions handbook page for how to add template suggestions based on the newly added language info.
Don't get me wrong, I'm not talking about putting my HTML next to the settings.py file but rather add the project directory (which does contains the settings.py file) in the TEMPLATE_DIR list so I can call any template by naming it 'app/template/file.html'.
I was just wondering why Django didn't come with template name space. It forces you either to:
create a template dir separate from all apps, then create a dir for each app and put your HTML in it.
create a template dir in each app dir and create another dir in it with the application name, then put the HTML in it.
This is less than ideal, since:
forces you to have your HTML outside your app. So much for being pluggable.
violates DRY by forcing you to create a redundant dir tree project_dir/app_name/template/appname otherwise if you have several templates named 'index.html', you are screwed big time.
So is it a bad idea to just define the project dir as a template dir to call all template files 'app_name/template/file.html'? If yes, why? How would you do it cleanly?
I personally use app_name/templates for app related templates and projects/templates for global templates. Personally I find this useful as i really like loose coupling between my apps and my projects, so I tend to keep them detached.
However django gives you freedom of choice. If you feel fine with you're choice I don't see any problem at all.
You make an interesting argument against the way app_directories template loader works. Other than polluting the app's root directory with templates, I cannot think of something going wrong because of this.
Perhaps it'd be worth investigating in making your own template loader instead?