What are the best practices for executing PHP code within a template in order to avoid syntax errors?

When executing PHP code within a template, it is important to properly escape the PHP code to avoid syntax errors. One common way to do this is by using the `<?php ?>` tags to encapsulate the PHP code within the template. Additionally, it is recommended to break out of the HTML context when writing PHP code by using `echo` or `print` statements to output dynamic content.

&lt;?php
// Example of executing PHP code within a template
$variable = &quot;Hello, World!&quot;;
?&gt;

&lt;div&gt;
    &lt;p&gt;&lt;?php echo $variable; ?&gt;&lt;/p&gt;
&lt;/div&gt;