phpBB

Development Wiki

New Template Commands in 3.1

From phpBB Development Wiki

Revision as of 13:00, 5 March 2012 by Brunoais (Talk | contribs)

This article lists new template commands available in phpBB 3.1

INCLUDEJS

This command queues external javascript file for inclusion in footer.

Syntax:
<!-- INCLUDEJS file.js -->
<!-- INCLUDEJS {VARNAME} -->
<!-- INCLUDEJS {$DEFINEDVARIABLE} -->

Path to .js file should be relative to style directory. Function can accept template variables, as displayed in sample code above.

Unlike using <script> tag, this command will put your script in the footer of the page between the inclusion of jQuery and </body>, allowing you to use jQuery in your script. It will also check styles tree for location of your file, which works similar to template inheritance. Scripts will be outputted in the same order as they were parsed via INCLUDEJS.

Example (full sample page, so you could see where code will appear):
<!-- overall_header.html -->
	header stuff here
	<!-- INCLUDEJS template/custom1.js -->
<!-- end of overall_header.html -->
<!-- custom template -->
	Some content
	<!-- INCLUDEJS template/custom2.js -->
<!-- end of custom template -->
<!-- overall_footer.html -->
	<!-- INCLUDEJS template/custom3.js -->
	footer code here
	jQuery is included here
	</body>
</html>
<!-- end of overall_footer.html -->
This will result in following HTML output:
header stuff here
some content
footer code here
jQuery is included here
<script src="./styles/prosilver/template/custom1.js"></script>
<script src="./styles/prosilver/template/custom2.js"></script>
<script src="./styles/prosilver/template/custom3.js"></script>
</body>
</html>

Script tag that was included via INCLUDEJS was moved to footer, the same order as they were in the markup, before </body> and path was changed to correct relative path to the .js file.