Below are examples of basic structures you need in templating shown in Twig (Drupal 8) and PHPTemplate (Drupal 7).
{# My code comment, won't appear in the HTML #}
<?php // My code comment, won't appear in the HTML ?>
<p>
Printing my variable: {{ my_variable }}
</p>
<p>
Printing my variable: <?php print $my_variable; ?>
</p>
Result if my variable is set to hello world!
:
<p>
Printing my variable: hello world!
</p>
{% if (variable) %}
<h1>My HTML</h1>
{% endif %}
<?php if ($variable): ?>
<h1>My HTML</h1>
<?php endif; ?>
{% set myContentId = 15 %}
<div id="node-{{ myContentId }}">
<?php $myContentId = 15; ?>
<div id="node-<?php print $myContentId; ?>">
Result: <div id="node-15">
{{ content.field_author }}
<?php print render($content['field_author']); ?>
{% for item in items %}
<div{{ item.attributes }}>
{{ item.content }}
</div>
{% endfor %}
<?php foreach ($items as $delta => $item): ?>
<div<?php print $item_attributes[$delta]; ?>>
<?php print render($item); ?>
</div>
<?php endforeach; ?>