I have inherited a php system written using Smarty. The code is split into class files and templates which I can work my way through. However, for each template file, there is another file written similarly to the template file but with a strange name. For example, I have a footer.tpl file with this code:
<div id="footer">
<p class="bold">Class Management, Version 3.6.4 (Version History/Change Log)</p>
<p> </p>
<p><img src="images/design/logo_small.gif" /></p>
<p>Work Limited</p>
<p>Registered Office: Work address</p>
<p>Tel: Work tel</p>
</div>
The accompanying file has the name %%0E^0E4^0E407559%%footer.tpl.php with the following code
<?php /* Smarty version 2.6.19, created on 2013-07-31 13:27:22
compiled from footer.tpl */ ?>
<div id="footer">
<p class="bold">Class Management, Version 3.6.4 (Version History/Change Log)</p>
<p> </p>
<p><img src="images/design/logo_small.gif" /></p>
<p>Work Limited</p>
<p>Registered Office: Work address</p>
<p>Tel: Work tel</p>
</div>
So, my question is, if I create a new template file, how could I create or what would I use to create the accompanying .tpl.php file?
Any pointers at all to give me a direction to start looking in gratefully received.
Many thanks.
That's a cached copy of the file, the variables are filled in (compiled) so next time its called it does not have to be recreated saving load time, processor time, bandwidth. You dont have to create that file your self they are handled internally. (assuming things are set up properly)
footer.tpl has no variables, some what unusual, so its not really an issue, but most template files should (have variables)
Related
I'm trying to use php-cs-fixer with a WordPress project, which means I (unfortunately) have files with a mix of PHP and HTML. I'm using the #PSR12 ruleset.
I'm having trouble with getting HTML within PHP control structures to indent correctly. Take this example snippet:
<?php if (!empty($related_posts)) : ?>
<div class="module--related_posts alignfull has-2-columns has-hover-state slider-on-mobile">
<h3 class="has-text-align-center">Related <?= esc_html($title) ?></h3>
</div>
<?php endif ?>
php-cs-fixer reformats it to:
<?php if (!empty($related_posts)) : ?>
<div class="module--related_posts alignfull has-2-columns has-hover-state slider-on-mobile">
<h3 class="has-text-align-center">Related <?= esc_html($title) ?>
</h3>
</div>
<?php endif ?>
Note the closing h3 tag has been moved to a new line, and the first-level indent within the if statement body has been removed.
The h3 issue I can live with, as this is resolved if I put the opening tag on its own line:
<h3 class="has-text-align-center">
Related <?= esc_html($title) ?>
</h3>
...but the lack of indent within the if statement is going to do my head in. The same thing happens with for and while statements.
Is there a rule in php-cs-fixer that I've overlooked that will resolve this?
The Answer of keradus on the "PHP code does not align with html code" issue:
PHP CS Fixer was never written with supporting mixed html/php file.
Some fixers are supporting one php part and one html part inside single file, but not big mix of them, like in template files.
If we would like to support template files, we would need to not only detect and track concrete fixers, but also provide some big integration test (like we do for Sf ruleset) that it remains to work for most important rules.
Before that happen, I would not claim that we officially support html/php mixed-files.
And in another answer:
we do not aim to fix mixed file (PHP and HTML in single file)
Not really an answer but I ended up just switching to PHP_CodeSniffer to get around this.
I have researched some answers that talk about php, javascript, iframes etc. but I have tried a couple and none of them work. I am new to HTML coding.. and coding in general!
<link rel="menu" href="menu.html"> does nothing
<!--#include virtual="/menu.html" --> does nothing (presumably because its a comment?)
<iframe src="page.html"></iframe>
or object... both place the menu in a silly little scroll box.
I want to run my menu on my page as if it were a function in C. Where I can just include it, and it be there, or just link it.
Thanks for the help!
Ryan
webpage file: biology.html
menu file: menu.html
<div class="container">
<img src="homeicon.jpg" width="50" alt="Home">
<div class="redhover">
<div class="dropdown">
<button class="dropbtn">GCSEs</button>
<div class="dropdown-content">
Chemistry
Biology
</div>
</div>
<div class="dropdown">
<button class="dropbtn">A-Levels</button>
<div class="dropdown-content">
Chemistry
Biology
</div>
</div>
<div class="dropdown">
<button class="dropbtn">University</button>
<div class="dropdown-content">
Telecommunications
Electronic Engineering
</div>
</div>
<div class="dropdown">
<button class="dropbtn">More</button>
<div class="dropdown-content">
About me
Youtube
</div>
</div>
</div>
</div>
You can use php to include files on other pages. Here is some example code to get you started:
<?php
require_once('menu.php');
?>
You can put this in your HTML page appropriately, however you must make sure that php can be processed on your server and the file containing php code must end in the .php extension.
There are also other methods of including files via php, see here:
http://php.net/manual/en/function.include.php
and
http://php.net/manual/en/function.require.php
Edit - I'm not a big fan of this approach, but it will work on Github pages.
Create a file called nav.js with your menu defined as a js variable, then use javascript to insert it into an empty div created on each page. This way to update your nav you only have to ever edit nav.js Not pretty but it works
nav.js
var navigation = "<nav>";
navigation += "<ul>";
navigation += "<li>Home</li>";
navigation += "<li>About</li>";
navigation += "</ul>";
navigation += "</nav>";
document.getElementById("navigation").innerHTML = navigation;
Other pages
<div id="navigation"></div>
<!--rest of page goes here.-->
<script src="nav.js"></script>
Fiddle: https://jsfiddle.net/ze3hLxx8/1/
There are multiple ways to include a file into another depending on the backend technology you wish / want / need to use.
PHP
The most common way to do it in php is by using the include or require statement inside a php file.
In your specific case your biology.html file must be converted to a biology.php file and then you can add the relative code to include the file:
<?php include('menu.php');?>
This simple statement will add the content in your menu.php file to the current page. This will not work if php is not present on the server and obviously will not work locally without a local development environment
The differences between require and include can be found on the official documentation:
include: http://php.net/manual/en/function.include.php
require: http://php.net/manual/en/function.require.php
SSI
Another method is to use Server Side Includes. To use the SSI it must be supported and enabled on the webserver. To use SSI you need to change the extension from biology.html to biology.shtml and then add the following statement:
<!--#include file="menu.html" -->
More information on server side includes can be found on wikipedia: https://en.wikipedia.org/wiki/Server_Side_Includes
This is a weird issue I ran into. Most likely something I am missing but after a few hours and searching over 200 files, I cannot find ANY reason for this to happen (yet it is anyway).
The amazing problem is that I have an override created for com_finder, I am doing this because you can only setup com_finder in one context and the site I am working on needs 2. So I copied com_finder and renamed it to com_finderhmg and did some find and replace to make it work exactly the same, just a different name and its own db tables.
Anyway it loads up fine but when I go to index I get a JS error from mootools, it basically says that a dom element does not exist (finderhmg-progress-container). Looking in the file i see that it is indeed there, but only in the source file, when I view source on the page it shows up as finder_hmg-progress-container.
Anyone else have this happen to them before? Or a something I might just be missing without realizing?
Here is the source file
<div id="finderhmg-indexer-container">
<br /><br />
<h1 id="finderhmg-progress-header"><?php echo JText::_('COM_FINDERHMG_INDEXER_HEADER_INIT'); ?></h1>
<p id="finderhmg-progress-message"><?php echo JText::_('COM_FINDERHMG_INDEXER_MESSAGE_INIT'); ?></p>
<form id="finderhmg-progress-form"></form>
<div id="finderhmg-progress-container"></div>
<input id="finderhmg-indexer-token" type="hidden" name="<?php echo JFactory::getSession()->getFormToken(); ?>" value="1" />
</div>
And the view source
<div id="finder_hmg-indexer-container">
<br /><br />
<h1 id="finder_hmg-progress-header">Starting Indexer</h1>
<p id="finder_hmg-progress-message">The indexer is being initialized. Do not close this window.</p>
<form id="finder_hmg-progress-form"></form>
<div id="finder_hmg-progress-container"></div>
<input id="finder_hmg-indexer-token" type="hidden" name="95b922cc6e0f81d18fd1e23e75a09d5f" value="1" />
</div>
There is no other file for the indexer, at least not that I know of (mass search of pretty much all of joomla yielded nothing).
This is very strange. However let's look at it the other way around. If your component outputs the code correctly, there can be only one piece of code that can change it, and that's a plugin (either a content plugin or a system plugin).
Try disabling all 3rd party content or system plugins until you find the one responsible for this behaviour.
I deploying my PHP project on CentOS and i using Zend Framework.
I have problem:
When i call an action from another action's view and it displayed is good on Windows Server but not good on CentOS Server. It's not load info in head tag when view source html.
Example:
In file: index.phtml (for index action in Product controller)
<div class="left">
<?php echo $this->action('left', $this->controller,'product',array('currentModule'=>$this->module)); ?>
</div>
<div class='right'>
<?php echo $this->action('list', $this->controller, 'product',array('currentModule'=>$this->module,'back'=> $this->back,'page'=> $this->page)); ?>
</div>
So, we can see. In index.phtml, i called 2 another action (left action and list action in Product controller). Windows is OK but on CentOS, this code is not work.
Please help me for it run on CentOS.
When i was try remove 2 this action:
<div class="left">
//code
</div>
<div class='right'>
//code
</div>
So, it's woking on CentOS :)
Thanks!
Windows migrations to unix based systems usually run into problems like this when you have case sensitivity issues - windows doesn't require case to be correct but unix does. Make sure your folders and php file names have the correct case and try it again - if not give us some of the errors your encountering and we could help more!
By the way, a little off topic here but the action view helper is not efficient, I would suggest looking into custom view helpers and the render view helper instead.
I've seen how Magento generates their templates but I am not sure how to do it myself in my application.
Basically we want to be able to define something similar to:
<template>
<section title="Recent Products">
<snippet name="products" />
</section>
</template>
Which in turn would be parsed.. somehow.. and render this code:
<h1>Recent products</h1>
<? include("Products"); ?>
(As an example...)
My main question is... is there anything written already that can do this? is there a term I can lookup online to get more information?
Thank you.