phpBB

Development Wiki

Difference between revisions of "New Template Commands in 3.1"

From phpBB Development Wiki

(INCLUDEJS)
(Fixed typos, improved english (sounds like it's still not perfect enough, though), and make some sentences more clear by decreasing the possibility of being interpreted using a wrong meaning.)
Line 10: Line 10:
 
Path to .js file should be relative to style directory. Function can accept template variables, as displayed in sample code above.
 
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 footer of page between 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 order that they were added in via INCLUDEJS.
+
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): <pre><!-- overall_header.html -->
 
Example (full sample page, so you could see where code will appear): <pre><!-- overall_header.html -->
Line 36: Line 36:
 
</body>
 
</body>
 
</html></pre>
 
</html></pre>
Script tag that was included via INCLUDEJS was moved to footer before &lt/body&gt; and path was changed to full path to .js file. Scripts were added in same order as they were included with.
+
Script tag that was included via INCLUDEJS was moved to footer, the same order as they were in the markup, before &lt;/body&gt; and path was changed to correct relative path to the .js file.

Revision as of 13:00, 5 March 2012

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.