Christian Bejarano Christian Bejarano - 1 year ago 64
HTML Question

What are these curly braces doing inside HTML?

I've found this code inside a project ( eCommerce website ) and I can't figure out what does the curly braces are doing inside HTML. I know Codeigniter is the framework used in this project and but I think they've put a bunch of other libraries .

<div class="category-tab">
<div class="col-sm-12">
<ul class="nav nav-tabs">
<a class="e; notranslate" e; href="#c{all_category_id}" data-toggle="tab">{all_category_name}</a>
<div class="tab-content">
<div class="tab-pane fade {all_category_active}" id="c{all_category_id}" >
<div class="col-sm-3">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<div style="width: 300px; height: 300px;">
<a href="{get_url}product_details/{product_id}">{product_image}</a>
<a href="{get_url}product_details/{product_id}"><p><span class = "text-capitalize e; notranslate" e;> {product_name}</ span></p></a>
<a href="javascript:;" class="btn btn-default add-to-cart" onclick="update_cart('{product_id}');">
<i class="fa fa-shopping-cart"></i> Agregar a carrito

Answer Source

It's not HTML code, it's template engine code.

In MVC frameworks, the views are distinct files containing HTML only, the server-side part being in the controller. Since we still need to put the shiny variables we compute in the controller somewhere, we still need to put some server-side code in the view.

In order for our views to not be filled with bits of PHP, Ruby or whatever, we write template code instead, which has a minimal syntaxic complexity. The template engines compiles then the view by replacing the template code with whatever server-side language your framework is based on. These are directly usable files that are generally stored in a cache directory and periodically recompiled.

You're right in that HTML doesn't uses curly brakcets, and that's precisely why they are pretty commonly used as delimiter for template code.

Template code can insert variables in the view, include a zone or subtemplate, add foreach to travel through arrays... But it's all replaced with PHP or whatever before the page is actually sent to a user.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download