Creating plugin to call mybb header template in Smarty 3 - php

I am working with a Smarty 3 script and I need to call mybb header and footer templates. I normally just create a .php page and put the eval code directly in it but I can't do that with smarty I have to make a plugin. Is it possible to make a plugin that calls templates from mybb?
The normal code to call mybb templates would be like..
<?php
define('IN_MYBB', 1); require "./global.php";
add_breadcrumb("Title here", "somename.php");
eval("\$html = \"".$templates->get("template_name")."\";");
output_page($html);
?>
I have never worked with Smarty let alone making plugins for this?

If you want to assign anything to variable in PHP using Smarty, you could use fetch() method.
For example in PHP:
$html = $smarty->fetch('template.tpl');
In Smarty template file:
This is template.
And after running it, you will have assigned This is template text to $html variable.

Related

Include PHP File in Smarty tpl

I want to include a PHP script that outputs some HTML in productdetail-full.tpl file (Smarty / Prestashop 1.6.x)
I tried:
{php}
include('show-stock-pos.php');
{/php}
AND
{include_php 'show-stock-pos.php'}
But they are both deprecated. Any suggestions?
Thanks!
You should use SmartyBC - Backwards Compatibility Wrapper for this since it's not recommended using php code in the templates.
Instead of:
require_once('path/to/smarty/libs/Smarty.class.php');
$smarty = new Smarty();
Use:
require_once('path/to/smarty/libs/SmartyBC.class.php');
$smarty = new SmartyBC();
And you will be able to use PHP in your Smarty template files.
More info about this here:
https://www.smarty.net/docs/en/bc.tpl
Prestashop is a modular system that uses hooks to display information.
According to Prestashop standards and solutions, you should use hooks and module:
Generate new module with a custom hook (or Use the available hook in the Productdetail-full.tpl file)
Get content of your PHP file in your module (using curl for example)
Pass your content to smarty
display content in your Hook

Drupal 8 custom templates tpl

Is there a way to integrate php instead of twig in Drupal8? Twig looks somewhat annoying. But in drupal 7 we could create tpl files with php syntaxes. Is there any way to create tpl files in Drupal 8 too. I am a beginner for drupal.
this is one of the major and finest change in D8 change template system in twig
in drupal7 no one recommend you to write php code like function or queries or any processing code in theme layer or template file
in drupal 8
HOOK_preprocess_page
and
HOOK_preprocess_node
are available same as in drupal 7
you have to write your code what you want in these fuctions and then send to the template what you want to print
like if you want print current user name in your template then do some thing like this
use HOOK function hook_preprocess_page
if you are writing code in your theme then write this code into your .theme file
if in module then in .module file
function themename_preprocess_page(&$variables) {
global $user;// current user object
$variables['customUserName'] = $user->getUsername();
}
change themename to your theme name if in module then replace with module name
in your twig template you will print this variable like this
{{ customUserName }}
we are overriding page template so your are able to get this variable in all you page templates
if you need this variable in node template then rename function to
function themename_preprocess_node(){}
hope this help you
thanks

Am I using Wordpress incorrectly?

I am new to web dev with WP. I just realized that I made my front page (it has a form to be filled out by a user) by putting the code for it in a php file (through CPanel) and using <?php include() ?> to use that php file in my index.php. However, I just noticed that WP has a Pages section where I can add code by simply surrounding it with <code></code>. What is the best practice here? Am I under-using the CMS that is Wordpress by not using this Pages section? Or is it ok to not use it?
you can use some pulgins to use php code in pages like "allow-php-in-posts-and-pages" . and if you want some php file then you have create a template for that and that temmplate should be add in wp-page .

Drupal variables in region templates

I'm doing my first totally custom Drupal 7 theme. I have the page.tpl.php file working fine and have header and footer regions working, until I move this:
<?php print render($page['main_menu']); ?>
into region--header.tpl.php - the menu is no longer generated - the html around the PHP is generated - nav etc. so I know drupal's reading the template file OK.
The same code works fine if it is in page.tpl.php
Any help greatly appreciated.
Main menu available as block. So you can just put him to this region. It's good practice.
Also don't forget to clear drupal/browser cache.
If you define custom variable in preprocess_page() or any other preprocess functions you shouldn't use render function, just use print $main_menu for example.
Also try check this

How to use shortcode in Magento phtml page

I have a short code
{{block type="ibtheme/product_list_featured" category_id="51" random_products="" template="catalog/product/list/featured.phtml"}}
which is working fine in editor from backend. How can U call the same short-code from a PHTML page ?
When I put the same code, it is printing a simple text.
phtml is php code, not cms html passed through a filter to catch the short codes (macros) and expand them out.
The contents between "{{" and "}}" must interpreted by a template engine and is only valid inside emails, CMS pages/blocks and the wysiwyg editors in the backend.
You put their equivalent into layout and call them as in the following ->
Magento Shortcode CMS block not working on product pages
In Magento CMS or Static block, if you want to add PHP code then you can just call any custom .phtml file by using following code. Like here I am including my_custom.phtml.
{{block type="core/template" name="myCustom" template="cms/my_custom.phtml"}}
This is equivalent to following layout tag:
<block type="core/template" name="myCustom" template="cms/my_custom.phtml">
Hope you find it useful.
The above answers are both incorrect if I'm reading that you would like to use shortcodes in phtml pages. I use these frequently, since we have a tremendous amount of content, and breaking them down in to phtml blocks is the easiest way for us to keep our content fresh.
Anyhow, here's the correct way to use call blocks in phtml:
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('cms/my_custom.phtml')->toHtml(); ?>
For Example, to use the block in your original answer would be
<?php echo $this->getLayout()->createBlock('ibtheme/product_list_featured')->setTemplate('catalog/product/list/featured.phtml')->toHtml(); ?>
I think this is what you're actually looking for. The code is in the CMS module in the Magento code.
<?php
// Load the cms helper
$helper = Mage::helper('cms');
// get the cms static block processor
$processor = $helper->getBlockTemplateProcessor();
// run the content with the shortcode through the filter
// in this case $item->getAnswer() contains a shortcode
$html = $processor->filter($item->getAnswer());
// print it to the page
echo $html;
?>
Remember anything is possible, just dig deeper. If in doubt, copy the Magento core code.

Categories