How to include a hbs template in a ftl - handlebars.js

All the posts and docs i've read about include is you could only include a ftl using #include. But is there a way to include handbelar hbs file into ftl?

Related

Where to search for the executed code from get_template_parts?

The WP theme I am working on uses get_template_part('foobar'); a lot in various places. Where should I search for the block's code? Is it in functions.php or in other files?
get_template_part('foobar'); is same as require 'foobar.php';. So you have a file named as foobar.php in your theme root directory.
See https://wordpress.stackexchange.com/questions/9978/how-to-use-get-template-part

How to make get_header() call a custom header file located in a sub-folder of the theme?

From a PHP template file located in a sub-folder of my WP theme folder (my_theme/subfolder/my_file.php) I want to use get_header() and call a custom header-new.php located in the same sub-folder.
Instead, get_header(header-new) loads header.php located in my theme root folder. How to fix that problem?
You are correct to use get_header() function. However, as per documentation you should pass the name of the custom header in the specific format - only the part that comes between 'header-' and '.php'. E.g. for the custom header in the file:
header-custom.php
you should use:
get_header('custom');
But that's not all. It is important to remember that the custom header file should be placed in 1 or 2 specific directories, depending on whether you're working on parent or child theme:
Parent theme: you should place it either in the same directory as the page template or the 'root' theme directory (specifically the same directory where your style.css is)
Child theme: you have to place it in the 'root' child theme directory
get_header() function calls locate_template() function, which searches for the custom header file in those 2 directories. If it doesn't find the file, it defaults to 'header.php'.
you can use :
get_template_part('header-new.php');
reference here: >https://developer.wordpress.org/reference/functions/get_template_part/

include header file out of themes folder wordpress

I have a file order.php exist at "website/order.php".
Question
I want to include header.php file into order.php file that exist at website/wp-content/themes/template/header.php . I am using this code in order.php file, but it is not working
include('wp-content/themes/business/header.php');
you can write below code:
include "wp-load.php";
get_header();

hook_preprocess_page() does not seem to use the suggested template file

I am suggesting a template file in the hook_preprocess_page() implementation done from a module, but the suggested template file doesn't seem to be used.
The template file is page--terminal-template.tpl.php, which is in the directory containing the module, and this is the implementation of hook_preprocess_page().
function terminal_preprocess_page(&$variables) {
if (arg(0) == "terminal") {
$variables['theme_hook_suggestions'][] = "page__terminal_template";
}
}
Could anyone please help me?
Preprocess and process functions can be implemented by modules. In fact, the documentation for theme() lists them when it shows in which order those functions are called.
The fact is that Drupal looks for the suggested template files in the theme directory. You have these alternatives:
Put the template files your module is suggesting in the directory containing the theme currently used
Follow what reported in Load view template on module activation to load the template files from the module directory
Suggest the template files you want to use in a preprocess function implemented by a theme
Following what reported in the other question, you would be able to use the template file found in the module directory. The only problem is that you would be using a generic template that could be different from the default page template used from the currently enabled theme.
If you are adding template files for the currently enabled theme, you should call drupal_theme_rebuild() to make Drupal rescan the directory containing the template files, after you added the new template file to the theme.
Actually, this hook can also be called from theme's template.php file along with module's hook.
Please refer Drupal 7 documentation here.
Say if your active theme is MY_THEME, then the code should be:
function MY_THEME_preprocess_page(&$variables) {
if (arg(0) == "terminal") {
$variables['theme_hook_suggestions'][] = "page__terminal_template";
}
}
And the template suggestions will work.
Edit: This functionality can also be implemented with Modules using hooks.

How to add a php file to wordpress theme addition of standard files?

Wordpress themes have standard file such as header.php, footer.php, index.php, functions.php, style.css, ...
How to add a php file to wordpress theme addition of standard files? for example I want add a news.php to display specific posts in it, please help me
Just add a new file (e.g. news.php), and put the template comment at the very beginning:
<?php
/*
Template Name: News Template
*/
Then, go to your Wordpress backend, create a new page, and select the template you created:

Resources