PHP is already a templating language. For example, this is what your example above would look like in PHP:
<? echo (something ? "text" : "other text") ?>
Think twice before adding another layer of complexity on top of this.
There are templating libraries like Smarty and they have their justification, for example caching, or when you want to separate code and design in a safe way (i.e. give designers something they can modify without breaking code). If it's just for your own use, though, then using native PHP is a very strong option.
The reason is to avoid mixing HTML with PHP and having spaghetti code
There is nothing wrong with using simple PHP inside your HTML code. (and whether you have spaghetti code in PHP or your new templating language doesn't really make a difference....)
What's bad (and leading to Spaghetti code) is mixing huge chunks of code with the HTML output, for example calculations or preparations. Those should always be separate from the HTML.
The PHP inside the HTML structure should do only simple comparisons, if/then/else
checks, for
/foreach
loops, and any operations directly related to outputting data (e.g. htmlspecialchars
or simple calculations).
If you stick to that, you can happily use native PHP for your templating needs.